<template>
  <div class="app-container">
    <div>
      <el-form :model="queryParams" ref="queryForm" :inline="true">
        <el-form-item label="">
          <el-date-picker format="YYYY" value-format="YYYY" style="width: 140px" v-model="queryParams.year" type="year" placeholder="请选择年份" />
        </el-form-item>
        <el-form-item label="">
          <el-input style="width: 140px" v-model="queryParams.organizationName" placeholder="单位" @focus="focusWorkArea('单位', 1)" />
        </el-form-item>
        <!-- <el-form-item label="">
          <el-select filterable v-model="queryParams.specialtyId" placeholder="专业" clearable style="width: 140px">
            <el-option v-for="dict in specialtyobj" :key="dict.id" :label="dict.specialty" :value="dict.id" />
          </el-select>
        </el-form-item> -->
        <el-form-item label="">
          <el-select filterable v-model="queryParams.maintainGradeId" placeholder="施工等级" clearable style="width: 140px">
            <el-option v-for="dict in constructionLevelobj" :key="dict.id" :label="dict.maintainGrade" :value="dict.id" />
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <el-input style="width: 140px" v-model="queryParams.maintainItem" placeholder="施工项目" />
        </el-form-item>
        <el-form-item label="">
          <el-select
            filterable
            collapse-tags
            collapse-tags-tooltip
            v-model="queryParams.examineStatus"
            placeholder="审批状态"
            clearable
            style="width: 140px"
          >
            <el-option v-for="dict in examineStatusobj" :key="dict.id" :label="dict.planAuditState" :value="dict.planAuditState" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleQuery" style="width: 90px">查询</el-button>
          <el-button @click="resetQuery" style="width: 90px">重置</el-button>
        </el-form-item>
      </el-form>
      <div class="concentDiv">
        <el-button type="primary" @click="intelligence" style="width: 90px">智能推荐</el-button>
        <div>
          <el-button type="primary" @click="PlanAdjustment" style="width: 90px">计划调整</el-button>
          <el-button type="primary" @click="submitForApproval" style="width: 90px">提交审批</el-button>
          <el-button type="primary" @click="handleAdd" style="width: 90px">新建</el-button>
        </div>
      </div>
      <el-table
        v-loading="loading"
        ref="multipleTable"
        :data="planList"
        height="57vh"
        :header-cell-class-name="headerCellClass"
        border
        @select="selectTab"
        :cell-style="cellStyle"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <el-table-column label="年份" prop="year"> </el-table-column>
        <el-table-column label="单位" prop="organizationName" />
        <el-table-column label="施工等级" prop="maintainGrade" />
        <el-table-column label="施工项目" prop="maintainItem" />
        <el-table-column label="施工地点" prop="maintainPlace" />
        <el-table-column label="施工时间" prop="maintainTime" />
        <el-table-column label="施工内容及影响范围" prop="maintainInfluenceScope" min-width="150">
          <template #default="scope">
            <span v-if="scope.row.outlineList.length < 2">
              <div v-for="item in scope.row.outlineList" :key="item.id">
                <span>
                  <p>施工内容:{{ item.maintainContent }}</p>
                  <p>影响范围:{{ item.affectScope }}</p>
                </span>
              </div>
            </span>
            <span v-else>
              <el-popover effect="dark" placement="top-start" :width="400" trigger="hover">
                <template #reference>
                  <div v-for="item in scope.row.outlineList" :key="item.id">
                    <span>
                      <p>施工内容:{{ item.maintainContent }}</p>
                      <p>影响范围:{{ item.affectScope }}</p>
                    </span>
                    <span>---</span>
                  </div>
                </template>
                <div v-for="item in scope.row.outlineList" :key="item.id">
                  <span>
                    <p>施工内容:{{ item.maintainContent }}</p>
                    <p>影响范围:{{ item.affectScope }}</p>
                  </span>
                </div>
              </el-popover>
            </span>
          </template>
        </el-table-column>
        <el-table-column label="工作量" prop="workload" min-width="150" />
        <el-table-column label="审批状态" prop="examineStatus" />
        <el-table-column label="流程步骤" prop="processSteps" />
        <el-table-column label="备注" prop="remark" />
        <el-table-column label="操作" fixed="right" min-width="200">
          <template #default="scope">
            <el-button link type="primary" @click="detailedFun(scope.row)">详情</el-button>
            <!-- 编辑的判断是，不在任务流程中，必须是创建人才能编辑，必须是驳回和草稿才能编辑 -->
            <el-button link type="primary" v-if="isShowfun(scope.row)" @click="editFun(scope.row)">编辑</el-button>
            <!-- v-if="scope.row.examineStatus == '审批中'" v-if="scope.row.isShowWorkId" -->
            <el-button link type="primary" v-if="scope.row.showExamine" @click="examineButtom(scope.row)">审批</el-button>
            <!-- 必须是创建人才能作废 -->
            <el-button
              v-if="scope.row.examineStatus == '驳回' && scope.row.createUser == userStore.id"
              link
              type="primary"
              @click="cancelFun(scope.row)"
              >作废</el-button
            >
            <el-button
              v-if="scope.row.examineStatus == '草稿' && scope.row.createUser == userStore.id"
              link
              type="primary"
              @click="handleDelete(scope.row)"
              >删除</el-button
            >
          </template>
        </el-table-column>
      </el-table>
    </div>
    <el-pagination
      :current-page="currentPage4"
      :page-size="pageSize4"
      :page-sizes="[10, 20, 30, 40]"
      background="background"
      layout="total, prev, pager, next, sizes, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <el-dialog title="智能推荐" v-model="isShowintelligenceDialog" width="80vw" append-to-body draggable>
      <intelligenceVue
        ref="ZNintelligenceVue"
        v-if="isShowintelligenceDialog"
        TableType="['工区','施工内容','影响范围','施工类型','行别','线名','不添加']"
        QueryType="['建议维修时间','单位','施工内容']"
      ></intelligenceVue>
    </el-dialog>
    <el-dialog title="单位" v-model="isShowWorkArea" width="350px" append-to-body draggable>
      <tree @handleCheckTree="handleCheckTree" v-if="isShowWorkArea" :organizationId="organizationId"></tree>
    </el-dialog>
    <!-- 添加或修改正线轨道设备-接头信息对话框 -->
    <el-dialog :title="title" v-model="open" width="1300px" append-to-body draggable @close="closeDialog" fullscreen>
      <div class="divclass">
        <div class="rightdiv">
          <div class="titlecla" v-if="!(isShowForm.indexOf('新增') != -1)">
            审批流转环节
            <div>
              <el-switch
                v-model="isShowselectionProcess"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #a8a8aa; margin-right: 5px; margin-bottom: 5px; vertical-align: top"
                inline-prompt
                active-text="显示"
                inactive-text="隐藏"
              />
            </div>
          </div>
          <div class="dialogClassleft" v-show="isShowselectionProcess">
            <div class="divzanwu" v-show="workIdParam == null">暂无预览图</div>
            <div v-if="workIdParam != null">
              <ProcessVue ref="ProcessVueRef" :workIdParam="workIdParam"></ProcessVue>
            </div>
          </div>
          <div class="titlecla">基础信息</div>
          <el-form ref="form" :model="forma" :rules="rules" label-width="5.5vw" :inline="true">
            <div class="inputDiv">
              <div>
                <el-form-item label="年份" prop="year">
                  <el-date-picker
                    :disabled="isShowForm.indexOf('编辑') != -1 || isShowForm.indexOf('详情') != -1"
                    format="YYYY"
                    value-format="YYYY"
                    style="width: 10vw"
                    v-model="forma.year"
                    type="year"
                    placeholder="请选择年份"
                    :disabled-date="disabledDate"
                  />
                </el-form-item>
                <el-form-item label="单位" prop="organizationName">
                  <el-input
                    style="width: 10vw"
                    :disabled="isShowForm.indexOf('编辑') != -1 || isShowForm.indexOf('详情') != -1"
                    v-model="forma.organizationName"
                    placeholder="请选择单位"
                    @focus="focusWorkArea('工区', 3)"
                  />
                </el-form-item>
              </div>
              <div>
                <!-- <el-form-item label="专业" prop="specialtyId" label-width="50px">
              <el-select
                :disabled="isShowForm.indexOf('详情') != -1"
                filterable
                clearable
                style="width: 180px"
                v-model="forma.specialtyId"
                placeholder="请选择"
              >
                <el-option v-for="dict in specialtyobj" :key="dict.id" :label="dict.specialty" :value="dict.id"></el-option>
              </el-select>
            </el-form-item> -->
                <el-form-item label="施工等级" prop="maintainGradeId">
                  <el-select
                    :disabled="isShowForm.indexOf('详情') != -1"
                    filterable
                    clearable
                    style="width: 13vw"
                    v-model="forma.maintainGradeId"
                    placeholder="请选择"
                  >
                    <el-option v-for="dict in constructionLevelobj" :key="dict.id" :label="dict.maintainGrade" :value="dict.id"></el-option>
                  </el-select>
                </el-form-item>
                <el-form-item label="施工项目" prop="maintainItem">
                  <!-- <el-input
                    style="width: 10vw"
                    :disabled="isShowForm.indexOf('编辑') != -1 || isShowForm.indexOf('详情') != -1"
                    v-model="forma.maintainItem"
                    placeholder="请输入施工项目"
                  /> -->
                  <el-input
                    :disabled="isShowForm.indexOf('编辑') != -1 || isShowForm.indexOf('详情') != -1"
                    v-model="forma.maintainItem"
                    placeholder="请输入施工项目"
                    style="width: 13vw"
                  >
                    <template #append
                      ><el-button
                        :disabled="isShowForm.indexOf('编辑') != -1 || isShowForm.indexOf('详情') != -1"
                        link
                        type="primary"
                        @click="maintainProjectFun(forma.maintainItem)"
                        icon="CirclePlusFilled"
                        class="CirclePlusFilled"
                      ></el-button
                    ></template>
                  </el-input>
                </el-form-item>
              </div>
              <div style="width: 32.5vw">
                <el-form-item label="施工时间" prop="maintainTime">
                  <el-input
                    :disabled="isShowForm.indexOf('详情') != -1"
                    style="width: 26vw"
                    v-model="forma.maintainTime"
                    placeholder="请输入施工时间"
                  />
                </el-form-item>
                <el-form-item label="施工地点" prop="maintainPlace">
                  <el-input
                    :disabled="isShowForm.indexOf('详情') != -1"
                    style="width: 26vw"
                    type="textarea"
                    v-model="forma.maintainPlace"
                    placeholder="请输入施工地点"
                  />
                </el-form-item>
              </div>
            </div>
            <div class="inputDiv">
              <el-form-item label="工作量" prop="workload">
                <el-input
                  type="textarea"
                  :disabled="isShowForm.indexOf('详情') != -1"
                  style="width: 23vw"
                  v-model="forma.workload"
                  placeholder="请输入工作量"
                />
              </el-form-item>
              <el-form-item label="备注" class="formItembz">
                <el-input
                  :disabled="isShowForm.indexOf('详情') != -1"
                  style="width: 26vw"
                  v-model="forma.remark"
                  type="textarea"
                  placeholder="请输入内容"
                ></el-input>
              </el-form-item>
            </div>
            <!-- <el-form-item label="流程步骤" prop="processSteps">
          <el-input v-model="forma.processSteps" placeholder="请输入流程步骤" />
        </el-form-item> -->
          </el-form>
          <div class="titlecla">
            施工内容及影响范围
            <div v-if="!(isShowForm.indexOf('详情') != -1)">
              智能推荐
              <el-switch
                v-model="isShowintelligence"
                style="--el-switch-on-color: #13ce66; --el-switch-off-color: #a8a8aa; margin-right: 5px; margin-bottom: 5px; vertical-align: top"
                inline-prompt
                active-text="显示"
                inactive-text="隐藏"
              />
            </div>
          </div>
          <div class="dialogClassleft" v-show="isShowForm.indexOf('详情') != -1 ? false : isShowintelligence">
            <div class="titlecla1">智能推荐</div>
            <intelligenceVue
              ref="intelligenceVueRef"
              v-if="open"
              DragType="搜索"
              TableType="['施工内容','影响范围','施工类型','行别','线名']"
              QueryType="['建议维修时间','里程','施工内容']"
              @intelligenceFun="intelligenceFun"
              :formaMaintainContentList="formaMaintainContentList"
              :workAreaTree="workAreaTree"
              heightTable="32vh"
            ></intelligenceVue>
          </div>
          <el-table :key="Math.random()" :data="forma.outlineList" max-height="608" style="min-height: 320px" border>
            <el-table-column label="" min-width="48px" v-if="!(isShowForm.indexOf('详情') != -1)">
              <template #default="scope">
                <div>
                  <Plus class="icon" @click="PlusIconFun(scope, scope.$index)"></Plus>
                  <Minus class="icon" @click="MinusIconFun(scope)"></Minus>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="序号" type="index" min-width="40px" v-if="isShowForm.indexOf('详情') != -1"> </el-table-column>
            <!-- <el-table-column label="任务id" prop="taskId">
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.taskId }}</span>
                  <el-input v-else disabled v-model="scope.row.taskId" placeholder="任务id" />
                </div>
              </template>
            </el-table-column> -->
            <el-table-column label="施工内容" prop="maintainContent">
              <template #header>
                <span class="tableHeader">施工内容</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.maintainContent }}</span>
                  <el-select
                    v-else
                    :disabled="scope.row.sources == '智能推荐池'"
                    filterable
                    clearable
                    v-model="scope.row.maintainContent"
                    placeholder="施工内容"
                  >
                    <el-option
                      v-for="dict in constructionContentobj"
                      :key="dict.id"
                      :label="dict.maintainContent"
                      :value="dict.maintainContent"
                    ></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="影响范围" prop="affectScope">
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.affectScope }}</span>
                  <el-input v-else v-model="scope.row.affectScope" placeholder="影响范围" />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="施工类型" prop="maintainType">
              <template #header>
                <span class="tableHeader">施工类型</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.maintainType }}</span>
                  <el-select
                    v-else
                    :disabled="scope.row.sources == '智能推荐池'"
                    filterable
                    clearable
                    v-model="scope.row.maintainType"
                    placeholder="施工类型"
                    @change="constructionTypeFun(scope.row.maintainType, scope.$index)"
                  >
                    <el-option
                      v-for="dict in maintainTypeobj"
                      :key="dict.maintainType"
                      :label="dict.maintainType"
                      :value="dict.maintainType"
                    ></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="线名" prop="railwayName">
              <template #header>
                <span class="tableHeader">线名</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.railwayName }}</span>
                  <el-select
                    v-else
                    :disabled="scope.row.sources == '智能推荐池'"
                    filterable
                    clearable
                    v-model="scope.row.railwayName"
                    placeholder="线名"
                  >
                    <el-option v-for="dict in railwayNameobj" :key="dict.id" :label="dict.railwayName" :value="dict.railwayName"></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="行别" prop="progressType">
              <template #header>
                <span class="tableHeader">行别</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.progressType }}</span>
                  <el-select
                    v-else
                    :disabled="scope.row.sources == '智能推荐池'"
                    filterable
                    clearable
                    v-model="scope.row.progressType"
                    placeholder="行别"
                  >
                    <el-option
                      v-for="dict in progressTypeobj"
                      :key="dict.progressType"
                      :label="dict.progressType"
                      :value="dict.progressType"
                    ></el-option>
                  </el-select>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="施工地段" prop="maintainDistrict" width="190px">
              <template #header>
                <span class="tableHeader">施工地段</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.maintainDistrict }}</span>
                  <el-input
                    v-else-if="
                      !(isShowForm.indexOf('详情') != -1) &&
                      scope.row.maintainType.slice(0, 3).indexOf('正线') != -1 &&
                      scope.row.maintainType.slice(0, 3).indexOf('桥隧涵') == -1
                    "
                    v-model="scope.row.maintainDistrict"
                    placeholder="施工地段"
                    @focus="constructionLotFocusFun(scope.$index)"
                    @blur="constructionLotFun(scope.$index)"
                  />
                  <span
                    v-else-if="
                      !(isShowForm.indexOf('详情') != -1) &&
                      scope.row.maintainType.slice(0, 3).indexOf('正线') == -1 &&
                      scope.row.maintainType.slice(0, 3).indexOf('桥隧涵') == -1
                    "
                  >
                    <el-popover
                      effect="dark"
                      placement="top-start"
                      :width="300"
                      trigger="hover"
                      :content="scope.row.maintainDistrict"
                      v-if="scope.row.maintainDistrict?.length != 0"
                    >
                      <template #reference>
                        <el-input v-model="scope.row.maintainDistrict" placeholder="施工地段" @focus="constructionLotFocusFun(scope.$index)" />
                      </template>
                      <span>{{ scope.row.maintainDistrict }}</span>
                    </el-popover>
                    <el-input
                      v-if="scope.row.maintainDistrict?.length == 0"
                      v-model="scope.row.maintainDistrict"
                      placeholder="施工地段"
                      @focus="constructionLotFocusFun(scope.$index)"
                    />
                  </span>
                  <span v-else-if="!(isShowForm.indexOf('详情') != -1) && scope.row.maintainType.slice(0, 3).indexOf('桥隧涵') != -1">
                    <el-input
                      title="格式:桥隧涵 K5+000-K6+000"
                      v-model="scope.row.maintainDistrict"
                      placeholder="施工地段"
                      @blur="constructionLotFun(scope.$index)"
                    >
                      <template #append v-if="scope.row.sources != '智能推荐池'"
                        ><el-button
                          title="格式:桥隧涵 K5+000-K6+000"
                          link
                          type="primary"
                          @click="constructionLotFocusFun(scope.$index)"
                          icon="CirclePlusFilled"
                          class="CirclePlusFilled"
                        ></el-button
                      ></template>
                    </el-input>
                    <!-- v-if="scope.row.sources != '智能推荐池'" -->
                    <!-- <el-button link type="primary" @click="constructionLotFocusFun(scope.$index)">添加</el-button> -->
                  </span>
                </div>
              </template>
            </el-table-column>
            <el-table-column label="施工数量" prop="maintainNum">
              <template #header>
                <span class="tableHeader">施工数量</span>
                <span style="color: #f67979">*</span>
              </template>
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">{{ scope.row.maintainNum }}</span>
                  <el-input v-else v-model="scope.row.maintainNum" disabled placeholder="施工数量" />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="备注" prop="remark">
              <template #default="scope">
                <div>
                  <span v-if="isShowForm.indexOf('详情') != -1">
                    <span v-if="scope.row.remark?.length <= 20">
                      {{ scope.row.remark }}
                    </span>
                    <span v-else-if="!scope.row.remark?.length"> --- </span>
                    <span v-else>
                      <el-popover effect="dark" placement="top-start" :width="400" trigger="hover" :content="scope.row.remark">
                        <template #reference> {{ scope.row.remark?.slice(0, 20) }}... </template>
                      </el-popover>
                    </span>
                  </span>
                  <el-input v-else v-model="scope.row.remark" placeholder="备注" />
                </div>
              </template>
            </el-table-column>
            <!-- <el-table-column label="日计划已完成的维修地段和维修数量" prop="none" v-if="isShowForm.indexOf('详情') != -1"> </el-table-column> -->
            <!-- <el-table-column label="执行进度" prop="none" v-if="isShowForm.indexOf('详情') != -1"> </el-table-column> -->
          </el-table>

    
          <div class="titlecla" v-if="isShowForm.indexOf('审批') != -1 && isShowForm.indexOf('计划调整') == -1">审批操作</div>
          <el-form
            ref="forms"
            v-if="isShowForm.indexOf('审批') != -1 && isShowForm.indexOf('计划调整') == -1"
            :model="examineForma"
            :rules="examineRules"
            label-width="100px"
            :inline="true"
          >
            <el-form-item label="处理节点" prop="nodeName">
              <el-input disabled v-model="examineForma.nodeName" placeholder="请输入处理节点" />
            </el-form-item>
            <el-form-item label="处理人" prop="userName">
              <el-input disabled v-model="examineForma.userName" placeholder="请输入处理人" />
            </el-form-item>
            <el-form-item label="审批意见" prop="action">
              <el-select clearable style="width: 180px" v-model="examineForma.action" placeholder="请选择">
                <el-option v-for="dict in ExamineFormobj" :key="dict.id" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item label="更多意见" prop="comment" :required="examineForma.action == 'jumpreject' || examineForma.action == 'reject'">
              <el-input
                style="width: 1058px"
                v-model="examineForma.comment"
                type="textarea"
                :autosize="{ minRows: 3, maxRows: 3 }"
                placeholder="请输入内容"
              />
            </el-form-item>
          </el-form>
          <div class="titlecla" v-if="isShowForm.indexOf('编辑') != -1 && isShowForm.indexOf('新增') == -1">
            操作轨迹
            <el-switch
              v-model="isShowOperationTrajectory"
              style="--el-switch-on-color: #13ce66; --el-switch-off-color: #a8a8aa; margin-right: 5px; margin-bottom: 5px; vertical-align: top"
              inline-prompt
              active-text="显示"
              inactive-text="隐藏"
            />
          </div>
          <div class="dialogcon" v-if="isShowForm.indexOf('编辑') != -1 && isShowForm.indexOf('新增') == -1 && isShowOperationTrajectory">
            <el-table :key="Math.random()" :data="operationTrajectory" height="30vh" border>
              <el-table-column label="序号" type="index"> </el-table-column>
              <el-table-column label="操作时间" prop="actiontime"> </el-table-column>
              <el-table-column label="操作人" prop="username"> </el-table-column>
              <el-table-column label="操作" prop="memo"> </el-table-column>
              <el-table-column label="审批意见" prop="actionName"> </el-table-column>
              <el-table-column label="更多意见" prop="comment"> </el-table-column>
            </el-table>
          </div>
          <div class="calssdivsub">
            <el-button v-if="isShowForm.indexOf('审批') != -1" type="success" @click="examineForm" style="width: 80px">提交</el-button>
            <el-button
              v-if="!(isShowForm.indexOf('详情') != -1) && isShowForm.indexOf('审批') == -1"
              type="success"
              @click="submitForApp('草稿')"
              style="width: 80px"
              >提交审批</el-button
            >
            <el-button
              v-if="isShowForm.indexOf('详情') != -1 ? false : isShowForm.indexOf('新增') != -1"
              type="primary"
              @click="submitForm('草稿')"
              style="width: 80px"
              >保存</el-button
            >
            <el-button @click="cancel" style="width: 80px">{{ isShowForm.indexOf("详情") != -1 ? "关闭" : "取消" }}</el-button>
          </div>
        </div>
      </div>
    </el-dialog>
    <el-dialog title="股道" v-model="isShowStaionTrack" width="550px" @close="TrackTurnoutDialog" append-to-body draggable>
      <el-table
        v-loading="loading"
        ref="TrackDialogRef"
        :data="stationTrackobj"
        height="50vh"
        border
        @select="selectTrack"
        @selection-change="selectstationTrack"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <el-table-column label="股道" prop="trackCode"> </el-table-column>
        <el-table-column label="车站" prop="stationName" />
        <el-table-column label="全长(m)" prop="totalLength" />
      </el-table>
    </el-dialog>
    <el-dialog title="道岔" v-model="isShowSwitch" width="550px" @close="TrackTurnoutDialog" append-to-body draggable>
      <el-table
        ref="TurnoutDialogRef"
        v-loading="loading"
        :data="TurnoutList"
        height="50vh"
        border
        @select="selectTurnout"
        @selection-change="selectstationTurnoutList"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <el-table-column label="道岔" prop="turnoutCode"> </el-table-column>
        <el-table-column label="车站" prop="stationName" />
      </el-table>
    </el-dialog>
    <el-dialog title="桥隧涵" v-model="isShowBridge" width="700px" append-to-body draggable>
      <el-table
        :header-cell-class-name="headerCellClass"
        ref="bridgeDialogRef"
        v-loading="loading"
        :data="bridgeList"
        height="40vh"
        border
        @select="selectstationbridgeList"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <el-table-column label="桥隧涵名称" prop="name" />
        <el-table-column label="中心里程" prop="centerMileageStr" />
        <el-table-column label="起点里程" prop="startingMileageStr" />
        <el-table-column label="终点里程" prop="destinationMileageStr" />
        <el-table-column label="全长(m)" prop="overallLength" />
      </el-table>
    </el-dialog>
    <el-dialog title="施工项目" v-model="constructionProjectShow" width="45vw" append-to-body draggable>
      <el-table
        :header-cell-class-name="headerCellClass"
        ref="constructionProjectRef"
        :data="constructionProject"
        height="40vh"
        border
        @select="selectMaintainProject"
      >
        <el-table-column type="selection" label="全选" width="50" />
        <el-table-column label="专业" prop="specialty" />
        <el-table-column label="细分专业" prop="subdivideSpecialty" />
        <el-table-column label="项目名称" prop="projectName" />
        <el-table-column label="是否周期项目" prop="periodProject">
          <template #default="scope">
            <span>{{ ["是", "否"][scope.row.periodProject] }}</span>
          </template>
        </el-table-column>
      </el-table>
    </el-dialog>
    <el-dialog title="提交审批" v-model="isShowselectionProcessDialog" width="700px" append-to-body draggable>
      <selectProcessVue
        v-if="isShowselectionProcessDialog"
        :isShowselectionProcessList="isShowselectionProcessList"
        @parentselectChangeionProcess="parentselectChangeionProcess"
        :submitCheckbox="submitCheckbox"
      ></selectProcessVue>
    </el-dialog>
    <el-dialog title="选择退回节点" v-model="returnNodeShow" width="400px" append-to-body draggable>
      <span style="font-size: 15px">退回节点:</span>
      <el-select clearable style="width: 180px" v-model="returnModel" placeholder="请选择">
        <el-option v-for="dict in returnFormobj" :key="dict.nodeId" :label="dict.nodeName" :value="dict.nodeId"></el-option>
      </el-select>
      <div class="calssdivsub">
        <el-button type="primary" @click="returnClickFun" style="width: 80px">提交</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script setup name="dayPlanCon">
import {
  //
  editManRailFacilityConnectorapi,
  selectWorkflowStatusapi,
  // selectUserByOrganizationIdapi,
  // examineConstructionPlanapi,
} from "@/api/main/api.js";
import {
  listMaintain,
  listprogresstype,
  listMaintaintype,
  //股道
  selectProDictionariesFacilityTrackList,
  //线名
  selectProDictionariesRailwayList,
  //道岔
  selectProDictionariesFacilityTurnoutList,
  listbridge,
  selectProDictionariesSpecialtyList,
  listMaintaingrade,
  listplan,
  selectProDictionariesConstructionProjectList,
} from "@/api/main/dataDictionary.js";
import { listYear, addYear, updateYear, deleteRelevanceById, examineMaintainPlan } from "@/api/main/yearPlan.js";
import useUserStore from "@/store/modules/user";
const userStore = useUserStore();
import intelligenceVue from "@/components/planModle/intelligence.vue";
import tree from "@/components/planModle/tree.vue";
import ProcessVue from "@/components/planModle/Process.vue";
import selectProcessVue from "@/components/planModle/selectProcess.vue";
import { nextTick, reactive, ref, toRefs } from "vue";
import axios from "axios";
const { proxy } = getCurrentInstance();
const router = useRouter();
const loading = ref(true);
const title = ref("年度施工计划新增");
const isShowForm = ref(["新增"]);
const open = ref(false);
const isShowintelligence = ref(true);
const isShowintelligenceDialog = ref(false);
const isShowWorkArea = ref(false);
const isShowOperationTrajectory = ref(false);

const data = reactive({
  // 基础数据-单位数据表格数据
  planList: [],
  // 查询参数
  queryParams: {
    pageNum: "1",
    pageSize: "10",
    year: "",
    organizationId: "",
    specialty: "",
    specialtyId: "",
    maintainGrade: "",
    maintainGradeId: "",
    maintainItem: "",
    examineStatus: "",
  },
  unitNameobj: [],
  // 表单参数
  forma: {},
  // 表单校验
  rules: {
    year: [{ required: true, message: "年份不能为空", trigger: ["blur", "change"] }],
    organizationName: [{ required: true, message: "单位不能为空", trigger: ["blur", "change"] }],
    specialtyId: [{ required: true, message: "专业不能为空", trigger: ["blur", "change"] }],
    maintainGradeId: [{ required: true, message: "施工等级不能为空", trigger: ["blur", "change"] }],
    maintainItem: [{ required: true, message: "施工项目不能为空", trigger: ["blur", "change"] }],
    maintainTime: [{ required: true, message: "施工日期不能为空", trigger: ["blur", "change"] }],
    maintainPlace: [{ required: true, message: "施工地点不能为空", trigger: ["blur", "change"] }],
    workload: [{ required: true, message: "工作量不能为空", trigger: ["blur", "change"] }],
  },
  examineRules: {
    nodeName: [{ required: true, message: "处理节点不能为空", trigger: ["blur", "change"] }],
    userName: [{ required: true, message: "处理人不能为空", trigger: ["blur", "change"] }],
    action: [{ required: true, message: "审批意见不能为空", trigger: ["blur", "change"] }],
    comment: [{ required: false, message: "更多意见不能为空", trigger: ["blur", "change"] }],
  },
  editobj: {},
  selecttabList: {},
  paramsintel: {},
  specialtyobj: [],
  constructionLevelobj: [],
  examineStatusobj: [],
  railwayNameobj: [],
  progressTypeobj: [],
  constructionContentobj: [],
  examineForma: {
    nodeName: "",
    userName: "",
    action: "",
    comment: "",
  },
  maintainTypeobj: [],
  operationTrajectory: [],
  stationTrackobj: [],
  isShowselectionProcessList: [],
  TurnoutList: [],
  workIdParam: "",
  bridgeList: [],
  ExamineFormobj: [],
  returnNodeShow: false,
  returnModel: "",
  returnFormobj: [],
  constructionProject: [],
});
const {
  constructionProject,
  returnFormobj,
  returnModel,
  returnNodeShow,
  ExamineFormobj,
  bridgeList,
  workIdParam,
  TurnoutList,
  isShowselectionProcessList,
  stationTrackobj,
  operationTrajectory,
  maintainTypeobj,
  examineForma,
  examineRules,
  constructionContentobj,
  progressTypeobj,
  railwayNameobj,
  examineStatusobj,
  constructionLevelobj,
  specialtyobj,
  dataTree,
  propsTree,
  paramsintel,
  selecttabList,
  queryParams,
  forma,
  rules,
  planList,
  unitNameobj,
  editobj,
} = toRefs(data);
function isShowfun(row) {
  // <!-- 编辑的判断是，不在任务流程中，必须是创建人才能编辑，必须是驳回和草稿才能编辑 -->
  if (row.showExamine) {
    return false;
  } else if (row.createUser == userStore.id && (row.examineStatus == "驳回" || row.examineStatus == "草稿")) {
    return true;
  }
}
function cellStyle({ row, column, rowIndex, columnIndex }) {
  // 根据状态列显示字体颜色
  if (row.examineStatus == "驳回") {
    return { color: "#fe0000" };
  } else {
    return "";
  }
}
//分页
const currentPage4 = ref(1);
const pageSize4 = ref(10);
const total = ref(10);
const handleSizeChange = (val) => {
  pageSize4.value = val;
  getList();
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val) => {
  currentPage4.value = val;
  getList();
  console.log(`current page: ${val}`);
};
function headerCellClass(row) {
  if (row.columnIndex === 0) {
    return "tabradio";
  }
}
//施工项目
const constructionProjectShow = ref(false);
function maintainProjectFun() {
  selectProDictionariesConstructionProjectList({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      constructionProject.value = res.data;
    }
    constructionProjectShow.value = true;
  });
}
const constructionProjectRef = ref(null);
//施工项目选择
function selectMaintainProject(selection, row) {
  // 清除所有勾选项的操作;
  constructionProjectRef.value.clearSelection();
  if (selection.length == 0) {
    return;
  }
  constructionProjectRef.value.toggleRowSelection(row, true);

  forma.value.maintainItem = row.projectName;
}
const multipleTable = ref("");
// 此时是将多选操作变成单选操作的函数的过程；
const selectTab = (selection, row) => {
  // 清除所有勾选项的操作;
  selecttabList.value = {};
  multipleTable.value.clearSelection();
  if (selection.length == 0) {
    return;
  }
  multipleTable.value.toggleRowSelection(row, true);
  selecttabList.value = row;
};
//桥隧道
const selectstationbridgeList = (selection, row) => {
  // 清除所有勾选项的操作;
  bridgeDialogRef.value.clearSelection();
  if (selection.length == 0) {
    return;
  }
  bridgeDialogRef.value.toggleRowSelection(row, true);
  let arrObj = forma.value.outlineList[isShowindex.value];
  arrObj.maintainDistrict = row.name + " " + row.startingMileageStr + "-" + row.destinationMileageStr;
  arrObj.maintainNum = constructionNumberFun1(isShowindex.value);
  arrObj.maintainNumberUnit = "m";
  arrObj.constructionNumberUnit = "m";
};

/** 搜索按钮操作 */
function handleQuery() {
  getList();
}
/** 查询列表 */
function getList() {
  queryParams.value.pageNum = currentPage4.value;
  queryParams.value.pageSize = pageSize4.value;

  for (let i = 0; i < specialtyobj.value.length; i++) {
    if (specialtyobj.value[i].id == queryParams.value.specialtyId) {
      queryParams.value.specialty = specialtyobj.value[i].specialty;
    }
  }
  for (let i = 0; i < constructionLevelobj.value.length; i++) {
    if (constructionLevelobj.value[i].id == queryParams.value.maintainGradeId) {
      queryParams.value.maintainGrade = constructionLevelobj.value[i].maintainGrade;
    }
  }

  queryParams.value.userId = sessionStorage.getItem("userId");
  queryParams.value.token = sessionStorage.getItem("accessToken");
  listYear(queryParams.value).then((res) => {
    if (res.code == 200) {
      let obj = {
        accessToken: sessionStorage.getItem("accessToken"),
        requestType: "TodoList",
      };
      planList.value = res.data;
      proxy.PsotaxiosFunction(obj, "todo/page").then((res) => {
        if (res.code == 0) {
          for (let i = 0; i < res.data.length; i++) {
            for (let a = 0; a < planList.value.length; a++) {
              const element = planList.value[a];
              if (element.workId == res.data[i].workId) {
                element.isShowWorkId = true;
              }
            }
          }
        }
      });

      loading.value = false;
      total.value = res.count;
    }
  });
}
getList();
/** 维修内容接口 */
function getList1() {
  listMaintain({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      constructionContentobj.value = res.data;
    }
  });
}
getList1();
/** 行别内容接口 */
function getList2() {
  listprogresstype({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      progressTypeobj.value = res.data;
    }
  });
}
getList2();
/** 施工类型接口 */
function getList3() {
  listMaintaintype({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      maintainTypeobj.value = res.data;
    }
  });
}
getList3();
/** 股道接口 */
function getList4() {
  selectProDictionariesFacilityTrackList({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      stationTrackobj.value = res.data;
    }
  });
}
getList4();
/** 线名接口 */
function getList5() {
  selectProDictionariesRailwayList({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      railwayNameobj.value = res.data;
    }
  });
}
getList5();
function getList6() {
  selectProDictionariesFacilityTurnoutList({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      TurnoutList.value = res.data;
    }
  });
}
getList6();
function getList7() {
  // listbridge({ hasDelete: 0 }).then((res) => {
  //   if (res.code == 200) {
  //     bridgeList.value = res.data;
  //   }
  // });
  selectProDictionariesSpecialtyList({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      specialtyobj.value = res.data;
    }
  });
  listMaintaingrade({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      constructionLevelobj.value = res.data;
    }
  });
  listplan({ hasDelete: 0 }).then((res) => {
    if (res.code == 200) {
      examineStatusobj.value = res.data;
    }
  });
}
getList7();
//审批流程记录
function getList8(row) {
  let obj = {
    accessToken: sessionStorage.getItem("accessToken"),
    workId: row.workId,
    skipFields: "isover;limittime;actionname;dotime;dotimemin;flowname;flowid;id",
  };
  proxy.PsotaxiosFunction(obj, "flow/support/history").then((res) => {
    if (res.code == 0) {
      for (let i = 0; i < res.data.length; i++) {
        const element = res.data[i];
        if (element.action == "Submit") {
          element.actionName = "同意";
        } else if (element.action == "Reject" || element.action == "Jumpreject") {
          element.actionName = "驳回";
        }
      }
      operationTrajectory.value = res.data;
    }
  });
}

function disabledDate(time) {
  // 禁用今天之前的日期
  return time.getTime() < Date.now() - 8.64e7; // 8.64e7 毫秒数代表一天
}
//智能推荐池拖过来的数据
function intelligenceFun(row) {
  // forma.value.workArea = row.workArea;
  //施工内容及影响范围
  for (let i = 0; i < forma.value.outlineList.length; i++) {
    const element = forma.value.outlineList[i];
    if (element.taskId == row.taskId) {
      forma.value.outlineList.splice(i, 1);
      if (i == 0) {
        forma.value.outlineList = [
          {
            type: "",
            sources: "手动新增",
            planId: "",
            taskId: proxy.uuidv4(),
            maintainContent: "",
            maintainContentId: "",
            railwayName: "",
            railwayId: "",
            maintainType: "",
            maintainTypeId: "",
            affectScope: "",
            progressType: "",
            progressTypeId: "",
            maintainDistrict: "",
            maintainNum: "",
            constructionNum: "",
            maintainNumberUnit: "",
            constructionNumberUnit: "",
            remark: "",
          },
        ];
      }
    }
  }
  let lengtha = forma.value.outlineList.length;
  if (
    forma.value.outlineList[lengtha - 1].maintainContent == "" &&
    forma.value.outlineList[lengtha - 1].affectScope == "" &&
    forma.value.outlineList[lengtha - 1].maintainType == "" &&
    forma.value.outlineList[lengtha - 1].railwayName == "" &&
    forma.value.outlineList[lengtha - 1].progressType == ""
  ) {
    forma.value.outlineList[lengtha - 1].type = row.type;
    forma.value.outlineList[lengtha - 1].sources = "智能推荐池";
    forma.value.outlineList[lengtha - 1].planId = "";
    forma.value.outlineList[lengtha - 1].taskId = row.taskId;
    forma.value.outlineList[lengtha - 1].maintainContent = row.maintainContent;
    forma.value.outlineList[lengtha - 1].maintainContentId = row.maintainContentId;
    forma.value.outlineList[lengtha - 1].railwayName = row.railwayName;
    forma.value.outlineList[lengtha - 1].railwayId = row.railwayId;
    forma.value.outlineList[lengtha - 1].maintainType = row.maintainType;
    forma.value.outlineList[lengtha - 1].maintainTypeId = row.maintainTypeId;
    forma.value.outlineList[lengtha - 1].affectScope = row.affectScope;
    forma.value.outlineList[lengtha - 1].progressType = row.progressType;
    forma.value.outlineList[lengtha - 1].progressTypeId = row.progressTypeId;
    forma.value.outlineList[lengtha - 1].maintainDistrict = row.unscheduledMaintainDistrict;
    //取的道岔和股道的个数和长度
    forma.value.outlineList[lengtha - 1].constructionNum = row.unscheduledMaintainNumber;
    forma.value.outlineList[lengtha - 1].maintainNumberUnit = row.maintainNumberUnit;
    forma.value.outlineList[lengtha - 1].constructionNumberUnit = row.maintainNumberUnit;
    forma.value.outlineList[lengtha - 1].remark = row.remark;
    //统计（1）
    forma.value.outlineList[lengtha - 1].maintainNum = constructionNumberFun1(lengtha - 1);
    //（1）
    if (row.maintainType.slice(0, 3).indexOf("桥隧涵") != -1) {
      forma.value.outlineList[lengtha - 1].maintainDistrict = row.btcName + " " + row.unscheduledMaintainDistrict;
      forma.value.outlineList[lengtha - 1].maintainNum = constructionNumberFun1(lengtha - 1);
    }
  } else {
    forma.value.outlineList.push({
      planId: "",
      type: row.type,
      sources: "智能推荐池",
      taskId: row.taskId,
      maintainContent: row.maintainContent,
      maintainContentId: row.maintainContentId,
      railwayName: row.railwayName,
      railwayId: row.railwayId,
      maintainType: row.maintainType,
      maintainTypeId: row.maintainTypeId,
      affectScope: row.affectScope,
      progressType: row.progressType,
      progressTypeId: row.progressTypeId,
      maintainDistrict: row.unscheduledMaintainDistrict,
      maintainNum: "",
      maintainNumberUnit: row.maintainNumberUnit,
      //取的道岔和股道的个数和长度
      constructionNum: row.unscheduledMaintainNumber,
      constructionNumberUnit: row.maintainNumberUnit,
      remark: row.remark,
    });
    if (row.maintainType.slice(0, 3).indexOf("桥隧涵") != -1) {
      forma.value.outlineList[lengtha].maintainDistrict = row.btcName + " " + row.unscheduledMaintainDistrict;
      forma.value.outlineList[lengtha].maintainNum = constructionNumberFun1(lengtha - 1);
    } else {
      //统计（1）
      forma.value.outlineList[lengtha].maintainNum = constructionNumberFun1(lengtha);
      //（1）
    }
  }
}
function formaMaintainContentList() {
  return forma.value.outlineList;
}
//重置
function resetQuery() {
  queryParams.value = {
    year: "",
    organizationId: "",
    specialty: "",
    specialtyId: "",
    maintainGrade: "",
    maintainGradeId: "",
    maintainItem: "",
    examineStatus: "",
  };
  getList();
}
//添加施工内容及影响范围
function PlusIconFun(row, index) {
  let objOneLis = forma.value.outlineList[index];
  if (objOneLis.maintainContent == "" && objOneLis.maintainType == "" && objOneLis.progressType == "" && objOneLis.railwayName == "") {
    if (objOneLis.sources != "智能推荐池") {
      forma.value.outlineList[index] = {
        type: "",
        sources: "手动新增",
        planId: "",
        taskId: proxy.uuidv4(),
        maintainContent: objOneLis.maintainContent,
        maintainContentId: objOneLis.maintainContentId,
        railwayName: objOneLis.railwayName,
        railwayId: objOneLis.railwayId,
        maintainType: objOneLis.maintainType,
        maintainTypeId: objOneLis.maintainTypeId,
        affectScope: objOneLis.affectScope,
        progressType: objOneLis.progressType,
        progressTypeId: objOneLis.progressTypeId,
        maintainDistrict: objOneLis.maintainDistrict,
        maintainNum: objOneLis.maintainNum,
        maintainNumberUnit: objOneLis.maintainNumberUnit,
        constructionNum: objOneLis.constructionNum,
        constructionNumberUnit: objOneLis.constructionNumberUnit,
        remark: objOneLis.remark,
      };
    }
  } else {
    forma.value.outlineList.push({
      type: "",
      sources: "手动新增",
      planId: "",
      taskId: proxy.uuidv4(),
      maintainContent: "",
      maintainContentId: "",
      railwayName: "",
      railwayId: "",
      maintainType: "",
      maintainTypeId: "",
      affectScope: "",
      progressType: "",
      progressTypeId: "",
      maintainDistrict: "",
      maintainNum: "",
      constructionNum: "",
      maintainNumberUnit: "",
      constructionNumberUnit: "",
      remark: "",
    });
  }
}
const intelligenceVueRef = ref(null);
// 删除施工内容及影响范围
function MinusIconFun(row) {
  if (forma.value.outlineList.length > 1) {
    forma.value.outlineList.splice(row.$index, 1);
  } else if (forma.value.outlineList.length == 1) {
    valueConstrion();
  }
  intelligenceVueRef.value.maintainchildrenFun();
}
//添加施工单位及负责人
// function PlusIconFunSG(row) {
//   forma.value.constructionUnitList.push({
//     userId: "",
//     planId: "",
//     createTime: "",
//     constructionUnit: "",
//     duty: "",
//     userName: "",
//     phone: "",
//   });
// }
// 删除施工单位及负责人
// function MinusIconFunSG(row) {
//   if (forma.value.constructionUnitList.length > 1) {
//     forma.value.constructionUnitList.splice(row.$index, 1);
//   }
// }
//添加配合单位及负责人
// function PlusIconFunPH(row) {
//   forma.value.cooperateUnitList.push({
//     userId: "",
//     planId: "",
//     createTime: "",
//     cooperateUnit: "",
//     duty: "",
//     userName: "",
//     phone: "",
//   });
// }
// 删除配合单位及负责人
// function MinusIconFunPH(row) {
//   if (forma.value.cooperateUnitList.length > 1) {
//     forma.value.cooperateUnitList.splice(row.$index, 1);
//   }
// }
//工区
const focusType = ref("");
const focusTypeIndex = ref("");
const organizationId = ref("");
function focusWorkArea(type, num, index) {
  focusType.value = num;
  focusTypeIndex.value = index;
  isShowWorkArea.value = true;
  organizationId.value = sessionStorage.getItem("organizationId");
  if (num == 5) {
    organizationId.value = "";
  }
}
const workAreaTree = ref({});
//树结构的选择单选
function handleCheckTree(data) {
  if (focusType.value == 1) {
    queryParams.value.organizationName = data.organizationFullName;
    queryParams.value.organizationId = data.organizationId;
  } else if (focusType.value == 3) {
    forma.value.organizationName = data.organizationFullName;
    forma.value.organizationId = data.organizationId;
    workAreaTree.value.workArea = data.organizationFullName;
    workAreaTree.value.workAreaId = data.organizationId;
    //选择工区后重新查询当前桥隧涵的数据
    listbridge({ hasDelete: 0, organizationId: forma.value.workAreaId }).then((res) => {
      bridgeList.value = [];
      if (res.code == 200) {
        bridgeList.value = res.data;
      }
    });
    if (intelligenceVueRef.value != null) {
      intelligenceVueRef.value.getList1();
    }
    for (let i = 0; i < forma.value.outlineList.length; i++) {
      if (i != -1) {
        let item = forma.value.outlineList[i];
        if (item.sources == "智能推荐池") {
          forma.value.outlineList.splice(i, 1);
          i--;
        }
      }
    }
    if (forma.value.outlineList.length == 0) {
      valueConstrion();
    }
  }
}
const ZNintelligenceVue = ref("");
//智能推荐
function intelligence() {
  isShowintelligenceDialog.value = true;
  nextTick(() => {
    ZNintelligenceVue.value.getList1();
  });
}
//选择流程
const isShowselectionProcess = ref(true);
//选择流程弹窗
const isShowselectionProcessDialog = ref(false);

function getAllNumbers(str) {
  // 使用正则表达式匹配所有数字
  const regex = /\d+/g;
  // 使用match()方法获取所有匹配的数字
  return str.match(regex);
}
const ProcessVueRef = ref("");
//详情
function detailedFun(row) {
  workIdParam.value = row.workId;
  console.log(workIdParam.value);
  getList8(row);
  open.value = true;
  //流程图默认显示
  isShowselectionProcess.value = true;
  //操作轨迹默认不展示
  isShowOperationTrajectory.value = false;
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  title.value = "年度施工计划详情";
  isShowForm.value = ["编辑", "详情"];
  nextTick(() => {
    console.log(ProcessVueRef.value);
    if (ProcessVueRef.value != "") {
      ProcessVueRef.value.getListSrc();
    }
  });
}
//编辑
function editFun(row) {
  examineForma.value = {
    nodeName: "",
    userName: "",
    action: "",
    comment: "",
  };
  workIdParam.value = row.workId;
  getList8(row);
  title.value = "年度施工计划编辑";
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  isShowForm.value = ["编辑", "新增"];
  isShowselectionProcess.value = false;
  if (forma.value.outlineList.length == 0) {
    valueConstrion();
  }
  open.value = true;
  nextTick(() => { 
    workAreaTree.value.workArea = forma.value.organizationName;
    workAreaTree.value.workAreaId = forma.value.organizationId;
    if (intelligenceVueRef.value != null) {
      intelligenceVueRef.value.getList1();
    }
    //选择工区后重新查询当前桥隧涵的数据
    listbridge({ hasDelete: 0, organizationId: forma.value.organizationId, organizationName:forma.value.organizationName }).then((res) => {
      bridgeList.value = [];
      if (res.code == 200) {
        bridgeList.value = res.data;
      }
    });
  });
  //编辑页面默认不展示智能推荐池
  isShowintelligence.value = false;
  // if (forma.value.constructionUnitList.length == 0) {
  //   forma.value.constructionUnitList = [
  //     {
  //       userId: "",
  //       planId: "",
  //       createTime: "",
  //       constructionUnit: "",
  //       duty: "",
  //       userName: "",
  //       phone: "",
  //     },
  //   ];
  // }
  // if (forma.value.cooperateUnitList.length == 0) {
  //   forma.value.cooperateUnitList = [
  //     {
  //       userId: "",
  //       planId: "",
  //       createTime: "",
  //       cooperateUnit: "",
  //       duty: "",
  //       userName: "",
  //       phone: "",
  //     },
  //   ];
  // }
}
function constructionTypeFun(row, index) {
  let arrObj = forma.value.outlineList[index];
  forma.value.outlineList[index].stationIdName = undefined;
  forma.value.outlineList[index].maintainDistrict = "";
  forma.value.outlineList[index].maintainNum = "";
  forma.value.outlineList[index].constructionNum = "";
  forma.value.outlineList[index].maintainNumberUnit = "";
  forma.value.outlineList[index].constructionNumberUnit = "";
  if (arrObj.maintainType.slice(0, 3).indexOf("正线") != -1) {
  } else if (arrObj.maintainType.slice(0, 3).indexOf("站线") != -1) {
  } else if (arrObj.maintainType.slice(0, 3).indexOf("道岔") != -1) {
  } else if (arrObj.maintainType.slice(0, 3).indexOf("桥隧涵") != -1) {
  } else if (arrObj.maintainType.slice(0, 3).indexOf("信号") != -1) {
  }
}
function kmUnit(m) {
  var v;
  if (typeof m === "number" && !isNaN(m)) {
    if (m >= 1000) {
      v = (m / 1000).toFixed(3) + "km";
    } else {
      v = m + "m";
    }
  } else {
    v = "0m";
  }
  return v;
}
function TurnoutUnit(m) {
  var v;
  if (typeof m === "number" && !isNaN(m)) {
    v = m + "组";
  } else {
    v = "0组";
  }
  return v;
}
// const
function toggleSelectionTableFun(name, key, index) {
  let arrLisr = [];
  if (name == "站线") {
    TrackDialogRef.value.clearSelection();
    arrLisr = stationTrackobj.value;
  }
  if (name == "道岔") {
    TurnoutDialogRef.value.clearSelection();
    arrLisr = TurnoutList.value;
  }
  //判断所有是站线的
  let stationArr = [];
  for (let ind = 0; ind < forma.value.outlineList.length; ind++) {
    const element = forma.value.outlineList[ind];
    if (element.maintainType.slice(0, 3).indexOf(name) != -1) {
      let arrConstructionLot = element.maintainDistrict.split(" ");
      //根据车站名称的股道和道岔Code来判断已经选择的数据做复选
      for (let i = 0; i < arrLisr.length; i++) {
        for (let a = 1; a < arrConstructionLot.length; a++) {
          //判断股道和道岔里面的车站名称和所选车站是不是一样的
          if (arrLisr[i].stationName == arrConstructionLot[0]) {
            // 这拼接的是车站id 车站名称 股道[row[i].stationId + row[i].stationName + "股道"]
            element.stationIdName = arrLisr[i].stationId + arrLisr[i].stationName + name;
            // console.log(element.stationIdName);
            //判断股道和道岔名称是否一样
            if (arrConstructionLot[a] == arrLisr[i][key]) {
              stationArr.push(arrLisr[i]);
            }
          }
        }
      }
    }
  }

  for (let i = 0; i < stationArr.length; i++) {
    if (name == "站线") {
      TrackDialogRef.value.toggleRowSelection(stationArr[i], true);
    }
    if (name == "道岔") {
      TurnoutDialogRef.value.toggleRowSelection(stationArr[i], true);
    }
  }
}
function toggleSelectionONETableFun() {
  bridgeDialogRef.value.clearSelection();
  let stationArr = [];
  for (let ind = 0; ind < forma.value.outlineList.length; ind++) {
    const element = forma.value.outlineList[ind];
    for (let i = 0; i < bridgeList.value.length; i++) {
      //判断桥隧涵名称是否一样
      if (element.maintainDistrict.split(" ")[0] == bridgeList.value[i].name) {
        stationArr.push(bridgeList.value[i]);
      }
    }
  }
  for (let i = 0; i < stationArr.length; i++) {
    bridgeDialogRef.value.toggleRowSelection(stationArr[i], true);
  }
}
//股道
const isShowStaionTrack = ref(false);
const TrackDialogRef = ref("");
const TurnoutDialogRef = ref("");
const bridgeDialogRef = ref("");
//道岔
const isShowSwitch = ref(false);
//桥隧涵
const isShowBridge = ref(false);
const isShowindex = ref("");
function constructionLotFocusFun(index) {
  let arrObj = forma.value.outlineList[index];
  if (arrObj.maintainType == "") {
    return proxy.$modal.msgError("请选择施工类型");
  }
  isShowindex.value = index;
  if (arrObj.maintainType.slice(0, 3).indexOf("正线") != -1) {
    arrObj.type = "线路保养修";
  } else if (arrObj.maintainType.slice(0, 3).indexOf("站线") != -1) {
    arrObj.type = "线路保养修";
    isShowStaionTrack.value = true;
    nextTick(() => {
      //回显表格选中
      toggleSelectionTableFun("站线", "trackCode", index);
    });
  } else if (arrObj.maintainType.slice(0, 3).indexOf("道岔") != -1) {
    arrObj.type = "线路保养修";
    isShowSwitch.value = true;
    nextTick(() => {
      //回显表格选中
      toggleSelectionTableFun("道岔", "turnoutCode", index);
    });
  } else if (arrObj.maintainType.slice(0, 3).indexOf("桥隧涵") != -1) {
    arrObj.type = "桥隧涵保养修";
    isShowBridge.value = true;
    nextTick(() => {
      //回显表格选中
      toggleSelectionONETableFun("桥隧涵", "turnoutCode");
    });
  } else if (arrObj.maintainType.slice(0, 3).indexOf("信号") != -1) {
    arrObj.type = "信号保养修";
  }
}
const ObjTrack = ref({});
const ObjTrackShow = ref(false);

//股道单选
function selectTrack(select, row) {
  ObjTrack.value = row;
  ObjTrack.value.stationIdName = row.stationId + row.stationName + "站线";
  ObjTrackShow.value = true;
}
//股道选择
function selectstationTrack(row) {
  let obj = {};
  for (let i = 0; i < row.length; i++) {
    if (obj[row[i].stationId + row[i].stationName + "站线"] == undefined) {
      obj[row[i].stationId + row[i].stationName + "站线"] = {};
      obj[row[i].stationId + row[i].stationName + "站线"].name = row[i].stationName + " " + row[i].trackCode;
      obj[row[i].stationId + row[i].stationName + "站线"].qcLength = Number(row[i].totalLength);
    } else {
      obj[row[i].stationId + row[i].stationName + "站线"].name = obj[row[i].stationId + row[i].stationName + "站线"].name + " " + row[i].trackCode;
      obj[row[i].stationId + row[i].stationName + "站线"].qcLength =
        Number(obj[row[i].stationId + row[i].stationName + "站线"].qcLength) + Number(row[i].totalLength);
    }
  }
  console.log(obj);
  let arrObj = forma.value.outlineList[isShowindex.value];
  //如果有多个车站，就有多条数据
  //把所以的idName 拿出来没有在数组中就加进去
  let arrTypeStationIdName = [];
  for (const key in obj) {
    arrTypeStationIdName.push(key);
    for (let i = 0; i < forma.value.outlineList.length; i++) {
      //如果全部数组中没有自己选择的车站和股道的话就再最后一个循环加一个。
      if (forma.value.outlineList[i].stationIdName == key) {
        forma.value.outlineList[i].maintainDistrict = obj[key].name;
        forma.value.outlineList[i].maintainNum = kmUnit(Number(obj[key].qcLength));
        forma.value.outlineList[i].constructionNum = Number(obj[key].qcLength);
        forma.value.outlineList[i].maintainNumberUnit = "m";
        forma.value.outlineList[i].constructionNumberUnit = "m";
        arrTypeStationIdName.splice(arrTypeStationIdName.length - 1, 1);
      }
    }
    if (arrObj.stationIdName == undefined) {
      let isShowselectnode = true;
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        if (forma.value.outlineList[i].stationIdName == ObjTrack.value.stationIdName) {
          isShowselectnode = false;
        }
      }
      if (isShowselectnode) {
        //赋值了一个车站ID加名称+用来判断是我加的还是智能推荐池的。;
        if (arrObj != undefined) {
          arrObj.stationIdName = ObjTrack.value.stationIdName;
          arrObj.maintainDistrict = obj[ObjTrack.value.stationIdName].name;
          arrObj.maintainNum = kmUnit(Number(obj[ObjTrack.value.stationIdName].qcLength));
          arrObj.constructionNum = Number(obj[ObjTrack.value.stationIdName].qcLength);
          arrObj.maintainNumberUnit = "m";
          arrObj.constructionNumberUnit = "m";
          arrTypeStationIdName.splice(arrTypeStationIdName.length - 1, 1);
        }
      }
    }
  }
  for (const key in obj) {
    //判断数字中之前有用过吗，没有用过就push进去。
    if (arrTypeStationIdName.indexOf(key) != -1) {
      forma.value.outlineList.push({
        stationIdName: key,
        type: "线路保养修",
        sources: "手动新增",
        planId: arrObj.planId,
        taskId: proxy.uuidv4(),
        maintainContent: arrObj.maintainContent,
        maintainContentId: arrObj.maintainContentId,
        railwayName: arrObj.railwayName,
        railwayId: arrObj.railwayId,
        maintainType: arrObj.maintainType,
        maintainTypeId: arrObj.maintainTypeId,
        affectScope: arrObj.affectScope,
        progressType: arrObj.progressType,
        progressTypeId: arrObj.progressTypeId,
        maintainDistrict: obj[key].name,
        maintainNum: kmUnit(Number(obj[key].qcLength)),
        constructionNum: Number(obj[key].qcLength),
        maintainNumberUnit: "m",
        constructionNumberUnit: "m",
        remark: arrObj.remark,
      });
    }
  }
  //判断当前取消选择的是哪个,就删除自己添加的哪个。
  if (ObjTrackShow.value == true) {
    if (!Object.hasOwnProperty.call(obj, ObjTrack.value.stationId + ObjTrack.value.stationName + "站线")) {
      console.log("减", ObjTrack.value.stationId.toString() + ObjTrack.value.stationName.toString() + "站线");
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        let element = forma.value.outlineList[i];
        if (element.sources == "手动新增") {
          if (element.stationIdName == ObjTrack.value.stationId.toString() + ObjTrack.value.stationName.toString() + "站线") {
            forma.value.outlineList.splice(i, 1);
            console.log(forma.value.outlineList[i]);
            if (forma.value.outlineList[i] == undefined) {
              isShowStaionTrack.value = false;
              if (forma.value.outlineList.length == 0) {
                valueConstrion();
                isShowStaionTrack.value = false;
              }
              return proxy.$modal.msgError("当前任务已取消选择,请重新选择任务。");
            }
          }
        }
      }
    }
  }

  // console.log(forma.value.outlineList);
}
function TrackTurnoutDialog() {
  ObjTurnoutShow.value = false;
  ObjTrackShow.value = false;
}
const ObjTurnout = ref({});
const ObjTurnoutShow = ref(false);
//道岔单选
function selectTurnout(select, row) {
  ObjTurnout.value = row;
  ObjTurnout.value.stationIdName = row.stationId + row.stationName + "道岔";
  ObjTurnoutShow.value = true;
}
//道岔
function selectstationTurnoutList(row) {
  let obj = {};
  for (let i = 0; i < row.length; i++) {
    if (obj[row[i].stationId + row[i].stationName + "道岔"] == undefined) {
      obj[row[i].stationId + row[i].stationName + "道岔"] = {};
      obj[row[i].stationId + row[i].stationName + "道岔"].name = row[i].stationName + " " + row[i].turnoutCode;
      obj[row[i].stationId + row[i].stationName + "道岔"].qcLength = 1;
    } else {
      obj[row[i].stationId + row[i].stationName + "道岔"].name = obj[row[i].stationId + row[i].stationName + "道岔"].name + " " + row[i].turnoutCode;
      obj[row[i].stationId + row[i].stationName + "道岔"].qcLength = Number(obj[row[i].stationId + row[i].stationName + "道岔"].qcLength) + 1;
    }
  }
  console.log(obj);
  let arrObj = forma.value.outlineList[isShowindex.value];
  //如果有多个车站，就有多条数据
  let arrTypeStationIdName = [];
  for (const key in obj) {
    arrTypeStationIdName.push(key);

    for (let i = 0; i < forma.value.outlineList.length; i++) {
      //如果全部数组中没有自己选择的车站和股道的话就再最后一个循环加一个。
      if (forma.value.outlineList[i].stationIdName == key) {
        forma.value.outlineList[i].maintainDistrict = obj[key].name;
        forma.value.outlineList[i].maintainNum = TurnoutUnit(Number(obj[key].qcLength));
        forma.value.outlineList[i].constructionNum = Number(obj[key].qcLength);
        forma.value.outlineList[i].maintainNumberUnit = "组";
        forma.value.outlineList[i].constructionNumberUnit = "组";
        arrTypeStationIdName.splice(arrTypeStationIdName.length - 1, 1);
      }
    }
    if (arrObj.stationIdName == undefined) {
      let isShowselectnode = true;
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        if (forma.value.outlineList[i].stationIdName == ObjTurnout.value.stationIdName) {
          isShowselectnode = false;
        }
      }
      if (isShowselectnode) {
        //赋值了一个车站ID加名称+用来判断是我加的还是智能推荐池的。;
        if (arrObj != undefined) {
          arrObj.stationIdName = ObjTurnout.value.stationIdName;
          arrObj.maintainDistrict = obj[ObjTurnout.value.stationIdName].name;
          arrObj.maintainNum = TurnoutUnit(Number(obj[ObjTurnout.value.stationIdName].qcLength));
          arrObj.constructionNum = Number(obj[ObjTurnout.value.stationIdName].qcLength);
          arrObj.maintainNumberUnit = "组";
          arrObj.constructionNumberUnit = "组";
          arrTypeStationIdName.splice(arrTypeStationIdName.length - 1, 1);
        }
      }
    }
  }
  for (const key in obj) {
    //判断数字中之前有用过吗，没有用过就push进去。
    if (arrTypeStationIdName.indexOf(key) != -1) {
      forma.value.outlineList.push({
        stationIdName: key,
        type: "线路保养修",
        sources: "手动新增",
        planId: arrObj.planId,
        taskId: proxy.uuidv4(),
        maintainContent: arrObj.maintainContent,
        maintainContentId: arrObj.maintainContentId,
        railwayName: arrObj.railwayName,
        railwayId: arrObj.railwayId,
        maintainType: arrObj.maintainType,
        maintainTypeId: arrObj.maintainTypeId,
        affectScope: arrObj.affectScope,
        progressType: arrObj.progressType,
        progressTypeId: arrObj.progressTypeId,
        maintainDistrict: obj[key].name,
        maintainNum: TurnoutUnit(Number(obj[key].qcLength)),
        constructionNum: Number(obj[key].qcLength),
        maintainNumberUnit: "组",
        constructionNumberUnit: "组",
        constructionNumberUnit: arrObj.constructionNumberUnit,
        remark: arrObj.remark,
      });
    }
  }
  //判断当前取消选择的是哪个,就删除自己添加的哪个。
  if (ObjTurnoutShow.value == true) {
    console.log(ObjTurnoutShow.value);
    if (!Object.hasOwnProperty.call(obj, ObjTurnout.value.stationId + ObjTurnout.value.stationName + "道岔")) {
      // console.log("减", ObjTurnout.value.stationId.toString() + ObjTurnout.value.stationName.toString() + "道岔");
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        let element = forma.value.outlineList[i];
        if (element.sources == "手动新增") {
          if (element.stationIdName == ObjTurnout.value.stationId.toString() + ObjTurnout.value.stationName.toString() + "道岔") {
            forma.value.outlineList.splice(i, 1);
            console.log(forma.value.outlineList[i]);
            if (forma.value.outlineList[i] == undefined) {
              isShowSwitch.value = false;
              if (forma.value.outlineList.length == 0) {
                valueConstrion();
                isShowSwitch.value = false;
              }
              return proxy.$modal.msgError("当前任务已取消选择,请重新选择任务。");
            }
          }
        }
      }
    }
  }

  // console.log(forma.value.outlineList);
}

//施工地段
function constructionLotFun(index) {
  if (forma.value.outlineList[index].maintainDistrict == "") {
    forma.value.outlineList[index].maintainNum = "";
    forma.value.outlineList[index].constructionNum = "";
    forma.value.outlineList[index].maintainNumberUnit = "";
    forma.value.outlineList[index].constructionNumberUnit = "";
  } else {
    forma.value.outlineList[index].maintainNum = constructionNumberFun1(index);
  }
}
function constructionNumberFun1(index) {
  let arrObj = forma.value.outlineList[index];
  if (arrObj.maintainType.slice(0, 3).indexOf("正线") != -1) {
    //维修里程的判断
    arrObj.type = "线路保养修";
    return determineFH(index);
  } else if (arrObj.maintainType.slice(0, 3).indexOf("站线") != -1) {
    arrObj.type = "线路保养修";
    if (arrObj.constructionNum.indexOf("m") == -1 || arrObj.constructionNum.indexOf("M") == -1) {
      return kmUnit(Number(arrObj.constructionNum));
    } else {
      return arrObj.constructionNum;
    }
  } else if (arrObj.maintainType.slice(0, 3).indexOf("道岔") != -1) {
    arrObj.type = "线路保养修";
    if (arrObj.constructionNum.indexOf("组") == -1) {
      return TurnoutUnit(Number(arrObj.constructionNum));
    } else {
      return arrObj.constructionNum;
    }
  } else if (arrObj.maintainType.slice(0, 3).indexOf("桥隧涵") != -1) {
    arrObj.type = "桥隧涵保养修";
    return lineFunBridge(index, "桥隧涵");
  } else if (arrObj.maintainType.slice(0, 3).indexOf("信号") != -1) {
    arrObj.type = "信号保养修";
  }
}
function lineFunBridge(index, type) {
  let arrList1 = forma.value.outlineList[index].maintainDistrict.split(" ");
  for (let i = 0; i < bridgeList.value.length; i++) {
    if (arrList1[0] == bridgeList.value[i].name) {
      if (
        arrList1[1].split("-")[0] == bridgeList.value[i].startingMileageStr &&
        arrList1[1].split("-")[1] == bridgeList.value[i].destinationMileageStr
      ) {
        forma.value.outlineList[index].constructionNum = "1";
        forma.value.outlineList[index].maintainNumberUnit = "座";
        forma.value.outlineList[index].constructionNumberUnit = "座";
        return "1座";
      } else {
        return determineFH(index);
      }
    }
  }
}
function determineFH(index) {
  let strLot = forma.value.outlineList[index].maintainDistrict;
  if (strLot == undefined) {
    strLot = "";
  }
  if (strLot.indexOf("；") != -1) {
    strLot = strLot.replace("；", ";");
  }
  forma.value.outlineList[index].constructionLotNumber = "";
  if (strLot.indexOf(";") != -1) {
    let aa = 0;
    for (let i = 0; i < strLot.split(";").length; i++) {
      const element = strLot.split(";")[i];
      if (i == 0) {
        forma.value.outlineList[index].constructionLotNumber = lineFun2(element, index);
      } else {
        forma.value.outlineList[index].constructionLotNumber += ";" + lineFun2(element, index);
      }

      aa += lineFun(element, index);
    }
    return kmUnit(Number(aa));
  } else {
    forma.value.outlineList[index].constructionLotNumber = lineFun2(strLot, index);
    return kmUnit(lineFun(strLot, index));
  }
}

//维修里程的判断 线路保养修
function lineFun(data, index) {
  //判断桥的长度。如果和总长度一样的话为1座
  let arr = data.split("-");
  let arr0 = "";
  let arr1 = "";
  if (arr[0] != undefined && arr[1] != undefined) {
    if (arr[0].indexOf("+") != -1 && arr[1].indexOf("+") != -1) {
      arr0 = arr[0].split("+");
      arr1 = arr[1].split("+");
      arr0 = subStringK(arr0);
      arr1 = subStringK(arr1);
      //给后台的总数
      forma.value.outlineList[index].constructionNum =
        Number(arr1[0] * 1000) + getFirstThreeDigits(arr1[1]) - Number(arr0[0] * 1000) - getFirstThreeDigits(arr0[1]);
      forma.value.outlineList[index].maintainNumberUnit = "m";
      forma.value.outlineList[index].constructionNumberUnit = "m";
      return Number(arr1[0] * 1000) + getFirstThreeDigits(arr1[1]) - Number(arr0[0] * 1000) - getFirstThreeDigits(arr0[1]);
    } else if (arr[0].indexOf("+") != -1 && arr[1].indexOf("+") == -1) {
      arr0 = arr[0].split("+");
      arr0 = subStringK(arr0);
      arr[1] = subStringK([arr[1]]);
      forma.value.outlineList[index].constructionNum = Number(arr[1] * 1000) - Number(arr0[0] * 1000) - getFirstThreeDigits(arr0[1]);
      forma.value.outlineList[index].maintainNumberUnit = "m";
      forma.value.outlineList[index].constructionNumberUnit = "m";
      return Number(arr[1] * 1000) - Number(arr0[0] * 1000) - getFirstThreeDigits(arr0[1]);
    } else if (arr[0].indexOf("+") == -1 && arr[1].indexOf("+") != -1) {
      arr1 = arr[1].split("+");
      arr1 = subStringK(arr1);
      arr[0] = subStringK([arr[0]]);
      forma.value.outlineList[index].constructionNum = Number(arr1[0] * 1000) + getFirstThreeDigits(arr1[1]) - Number(arr[0] * 1000);
      forma.value.outlineList[index].maintainNumberUnit = "m";
      forma.value.outlineList[index].constructionNumberUnit = "m";
      return Number(arr1[0] * 1000) + getFirstThreeDigits(arr1[1]) - Number(arr[0] * 1000);
    } else if (arr[0].indexOf("+") == -1 && arr[1].indexOf("+") == -1) {
      arr[1] = subStringK([arr[1]]);
      arr[0] = subStringK([arr[0]]);
      forma.value.outlineList[index].constructionNum = Number(arr[1] * 1000) - Number(arr[0] * 1000);
      forma.value.outlineList[index].maintainNumberUnit = "m";
      forma.value.outlineList[index].constructionNumberUnit = "m";
      return Number(arr[1] * 1000) - Number(arr[0] * 1000);
    }
  }
}
//给后台字符串的处理
function lineFun2(data, index) {
  //判断桥的长度。如果和总长度一样的话为1座
  let arr = data.split("-");
  let arr0 = "";
  let arr1 = "";
  if (arr[0] != undefined && arr[1] != undefined) {
    if (arr[0].indexOf("+") != -1 && arr[1].indexOf("+") != -1) {
      arr0 = arr[0].split("+");
      arr1 = arr[1].split("+");
      arr0 = subStringK(arr0);
      arr1 = subStringK(arr1);
      //给后台的以-号分开的值
      return (arr0[0] * 1000 + getFirstThreeDigits(arr0[1])).toString() + "-" + (arr1[0] * 1000 + getFirstThreeDigits(arr1[1])).toString();
    } else if (arr[0].indexOf("+") != -1 && arr[1].indexOf("+") == -1) {
      arr0 = arr[0].split("+");
      arr0 = subStringK(arr0);
      arr[1] = subStringK([arr[1]]);
      return (arr0[0] * 1000 + getFirstThreeDigits(arr0[1])).toString() + "-" + (arr[1] * 1000).toString();
    } else if (arr[0].indexOf("+") == -1 && arr[1].indexOf("+") != -1) {
      arr1 = arr[1].split("+");
      arr1 = subStringK(arr1);
      arr[0] = subStringK([arr[0]]);
      return (arr[0] * 1000).toString() + "-" + (arr1[0] * 1000 + getFirstThreeDigits(arr1[1])).toString();
    } else if (arr[0].indexOf("+") == -1 && arr[1].indexOf("+") == -1) {
      arr[1] = subStringK([arr[1]]);
      arr[0] = subStringK([arr[0]]);
      return (arr[0] * 1000).toString() + "-" + (arr[1] * 1000).toString();
    }
  }
}
function getFirstThreeDigits(number) {
  // 转换为字符串
  const numberStr = number.toString();
  // 获取前三位
  const firstThree = numberStr.substring(0, 3);
  // 将前三位字符串转换回数字
  return parseInt(firstThree, 10);
}
function subStringK(row) {
  let index = row[0].lastIndexOf("K");
  row[0] = row[0].substring(index + 1, row[0].length);
  return row;
}

function valueConstrion() {
  forma.value.outlineList = [
    {
      type: "",
      sources: "手动新增",
      planId: "",
      taskId: proxy.uuidv4(),
      maintainContent: "",
      maintainContentId: "",
      railwayName: "",
      railwayId: "",
      maintainType: "",
      maintainTypeId: "",
      affectScope: "",
      progressType: "",
      progressTypeId: "",
      maintainDistrict: "",
      maintainNum: "",
      constructionNum: "",
      maintainNumberUnit: "",
      constructionNumberUnit: "",
      remark: "",
    },
  ];
}

//审批
function examineButtom(row) {
  // console.log(row);
  examineForma.value = {
    nodeName: "",
    userName: "",
    action: "",
    comment: "",
  };
  workIdParam.value = row.workId;
  getList8(row);
  title.value = "年度施工计划审批";
  editobj.value = JSON.parse(JSON.stringify(row));
  forma.value = JSON.parse(JSON.stringify(row));
  if (row.isReader == 1 || row.examineStatus == "驳回") {
    isShowForm.value = ["编辑", "审批"];
    //查阅式审批
  } else {
    isShowForm.value = ["编辑", "详情", "审批"];
  }
  // 查询审批按钮
  let obj = {
    accessToken: sessionStorage.getItem("accessToken"),
    workId: row.workId,
    subjectionId: row.subjectionId ? row.subjectionId : "",
    trackId: row.trackId,
    token: sessionStorage.getItem("accessToken"),
  };
  selectWorkflowStatusapi(obj).then((res) => {
    if (res.code == 200) {
      ExamineFormobj.value = [];
      examineForma.value.nodeName = res.data.nodeName;
      examineForma.value.userName = res.data.userName;
      examineForma.value.accessToken = sessionStorage.getItem("accessToken");
      examineForma.value.workId = res.data.workId;
      examineForma.value.trackId = res.data.trackId;
      examineForma.value.subjectionId = res.data.subjectionId;
      examineForma.value.nodeId = res.data.nodeId;
      examineForma.value.planId = forma.value.id;
      examineForma.value.isReader = row.isReader;
      if (res.data.flowButtons != null) {
        for (let i = 0; i < res.data.flowButtons.length; i++) {
          const element = res.data.flowButtons[i];
          if (element.buttonName == "提交") {
            ExamineFormobj.value.push({
              label: "同意",
              value: "submit",
            });
          } else if (element.buttonName == "退回") {
            ExamineFormobj.value.push({
              label: "驳回",
              value: "reject",
            });
          } else if (element.buttonName == "任意退回") {
            ExamineFormobj.value.push({
              label: "任意驳回",
              value: "jumpreject",
            });
          }
        }
      }
      open.value = true;
      //流程图默认显示
      isShowselectionProcess.value = true;
      //操作轨迹默认不展示
      isShowOperationTrajectory.value = false;
      nextTick(() => {
        if (ProcessVueRef.value != "") {
          ProcessVueRef.value.getListSrc();
        }
        workAreaTree.value.workArea = forma.value.organizationName;
    workAreaTree.value.workAreaId = forma.value.organizationId;
        if (intelligenceVueRef.value != null) {
          intelligenceVueRef.value.getList1();
        }
        //选择工区后重新查询当前桥隧涵的数据
        listbridge({ hasDelete: 0, organizationId: forma.value.organizationId, organizationName: forma.value.organizationName }).then((res) => {
          bridgeList.value = [];
          if (res.code == 200) {
            bridgeList.value = res.data;
          }
        });
      });
    }
  });
}
function closeDialog() {
  isShowForm.value = ["新增"];
  workIdParam.value = null;
  getList();
  bridgeList.value = [];
}
// 取消按钮
function cancel() {
  open.value = false;
}
function clear() {
  forma.value = {
    year: "",
    organizationName: "",
    organizationId: "",
    specialty: "",
    specialtyId: "",
    maintainGrade: "",
    maintainGradeId: "",
    maintainItem: "",
    maintainPlace: "",
    maintainTime: "",
    workload: "",
    constructionLocation: "",
    lockoutTime: "",
    outlineList: [
      {
        type: "",
        sources: "手动新增",
        planId: "",
        taskId: proxy.uuidv4(),
        maintainContent: "",
        maintainContentId: "",
        railwayName: "",
        railwayId: "",
        maintainType: "",
        maintainTypeId: "",
        affectScope: "",
        progressType: "",
        progressTypeId: "",
        maintainDistrict: "",
        maintainNum: "",
        constructionNum: "",
        maintainNumberUnit: "",
        constructionNumberUnit: "",
        remark: "",
      },
    ],
    trafficModeChange: "",
    equipmentChange: "",
    // constructionUnitList: [
    //   {
    //     userId: "",
    //     planId: "",
    //     createTime: "",
    //     constructionUnit: "",
    //     duty: "",
    //     userName: "",
    //     phone: "",
    //   },
    // ],
    // cooperateUnitList: [
    //   {
    //     userId: "",
    //     planId: "",
    //     createTime: "",
    //     cooperateUnit: "",
    //     duty: "",
    //     userName: "",
    //     phone: "",
    //   },
    // ],
    processSteps: "",
    examineStatus: "",
    remark: "",
    hasDelete: "",
    createTime: "",
  };
  examineForma.value = {
    nodeName: "",
    userName: "",
    action: "",
    comment: "",
  };
}
/** 新增按钮操作 */
function handleAdd() {
  open.value = true;
  closeDialog();
  clear();
  title.value = "年度施工计划新增";
  //新增不展示流程图
  isShowselectionProcess.value = false;
}

const submitCheckbox = ref({});
//单选提交审批
function submitForApproval() {
  if (selecttabList.value.id == undefined) {
    return proxy.$modal.msgError("请选择任务");
  }
  if (selecttabList.value.examineStatus == "草稿") {
    if (selecttabList.value.createUser != sessionStorage.getItem("userId")) {
      return proxy.$modal.msgError("此任务当前用户无操作权限");
    }
    proxy.$modal
      .confirm("请确定是否提交审批？")
      .then(() => {
        let obj = {
          accessToken: sessionStorage.getItem("accessToken"),
          isCreate: true,
          templateType: "年计划-年度施工轮廓计划-审批",
          planId: selecttabList.value.id,
          action: "submit",
          examineStatus: 1,
        };
        examineMaintainPlan(obj).then((res) => {
          if (res.code == 200) {
            open.value = false;
            getList();
            return proxy.$modal.msgSuccess("提交成功");
          } else if (res.code == 4) {
            submitCheckbox.value = res.data;
            //判断是不是首页的单选提交审批
            isSubmitWork.value = false;
            //判断是不是驳回,false不是
            cancelFunsubmit.value = false;
            isShowselectionProcessDialog.value = true;
          }
        });
      })
      .catch(() => {});
  } else {
    return proxy.$modal.msgError("该计划已提交流程");
  }
}
//提交审批中的确认
function parentselectChangeionProcess(radioSelectlistUserList, isReader, selectlistUserList) {
  submitCheckbox.value.accessToken = sessionStorage.getItem("accessToken");
  //判断是不是先点的作废如果是的话直接赋值isCance = true 如果不是的话就判断examineStatus == "作废审核中"
  if (cancelFunsubmit.value == true) {
    submitCheckbox.value.isCance = true;
  } else {
    if (forma.value.examineStatus == "作废审核中" || forma.value.examineStatus == "作废驳回") {
      submitCheckbox.value.isCance = true;
    } else {
      submitCheckbox.value.isCance = false;
    }
  }

  //通过当前条的提交审批过来的,提交按钮    和作废按钮
  if (isSubmitWork.value) {
    if (forma.value.examineStatus == "驳回" && examineForma.value.action == "submit") {
      submitCheckbox.value.examineStatus = 1;
    } else {
      submitCheckbox.value.examineStatus = 0;
    }
    //判断是作废过来的值
    if (cancelFunsubmit.value == true) {
      submitCheckbox.value.action = "submit";
    }
    if (submitCheckbox.value.selectType == "radio") {
      submitCheckbox.value.userIds = radioSelectlistUserList.userId;
      submitCheckbox.value.isReader = isReader;
      submitCheckbox.value.comment = submitCheckbox.value.comment;
      submitCheckbox.value.selectAuthor = [radioSelectlistUserList];
      examineMaintainPlan(submitCheckbox.value).then((res) => {
        if (res.code == 200) {
          proxy.$modal.msgSuccess("提交成功");
          isShowselectionProcessDialog.value = false;
          open.value = false;
          getList();
          workIdParam.value = null;
          workIdParam.value = forma.value.workId;
        }
      });
    } else if (submitCheckbox.value.selectType == "checkbox") {
      for (let i = 0; i < selectlistUserList.length; i++) {
        const element = selectlistUserList[i];
        if (i == 0) {
          submitCheckbox.value.userIds = element.userId;
        } else {
          submitCheckbox.value.userIds += ";" + element.userId;
        }
      }
      submitCheckbox.value.selectAuthor = selectlistUserList;
      submitCheckbox.value.isReader = isReader;
      submitCheckbox.value.comment = submitCheckbox.value.comment;
      examineMaintainPlan(submitCheckbox.value).then((res) => {
        if (res.code == 200) {
          proxy.$modal.msgSuccess("提交成功");
          isShowselectionProcessDialog.value = false;
          open.value = false;
          getList();
          workIdParam.value = null;
          workIdParam.value = forma.value.workId;
        }
      });
    }
    //首页上的提交审批按钮    和新增的提交审批按钮 这永远是第一次提交审批
  } else {
    if (submitCheckbox.value.selectType == "radio") {
      submitCheckbox.value.userIds = radioSelectlistUserList.userId;
      submitCheckbox.value.isReader = isReader;
      submitCheckbox.value.comment = "";
      submitCheckbox.value.selectAuthor = [radioSelectlistUserList];
      submitCheckbox.value.examineStatus = 1;
      submitCheckbox.value.action = "submit";
      examineMaintainPlan(submitCheckbox.value).then((res) => {
        if (res.code == 200) {
          proxy.$modal.msgSuccess("提交成功");
          isShowselectionProcessDialog.value = false;
          open.value = false;
          getList();
          workIdParam.value = null;
          workIdParam.value = forma.value.workId;
        }
      });
    } else if (submitCheckbox.value.selectType == "checkbox") {
      for (let i = 0; i < selectlistUserList.length; i++) {
        const element = selectlistUserList[i];
        if (i == 0) {
          submitCheckbox.value.userIds = element.userId;
        } else {
          submitCheckbox.value.userIds += ";" + element.userId;
        }
      }
      submitCheckbox.value.selectAuthor = selectlistUserList;
      submitCheckbox.value.isReader = isReader;
      submitCheckbox.value.comment = "";
      submitCheckbox.value.examineStatus = 1;
      submitCheckbox.value.action = "submit";
      examineMaintainPlan(submitCheckbox.value).then((res) => {
        if (res.code == 200) {
          proxy.$modal.msgSuccess("提交成功");
          isShowselectionProcessDialog.value = false;
          open.value = false;
          getList();
          workIdParam.value = null;
          workIdParam.value = forma.value.workId;
        }
      });
    }
  }
}

//计划调整 选中未关联日计划、审批状态为审批通过的计划
function PlanAdjustment() {
  if (selecttabList.value.id == undefined) {
    return proxy.$modal.msgError("请选择任务");
  }
  if (selecttabList.value.examineStatus == "审核通过") {
    //保存按钮
    title.value = "年度施工计划调整";
    isShowForm.value = ["编辑", "计划调整"];
    forma.value = JSON.parse(JSON.stringify(selecttabList.value));
    getList8(forma.value);
    workIdParam.value = forma.value.workId;
    if (forma.value.outlineList.length == 0) {
      valueConstrion();
    }
    // if (forma.value.maintainUnitList.length == 0) {
    //   forma.value.maintainUnitList = [
    //     {
    //       userId: "",
    //       planId: "",
    //       createTime: "",
    //       maintainUnit: "",
    //       duty: "",
    //       userName: "",
    //       phone: "",
    //     },
    //   ];
    // }
    // if (forma.value.cooperateUnitList.length == 0) {
    //   forma.value.cooperateUnitList = [
    //     {
    //       userId: "",
    //       planId: "",
    //       createTime: "",
    //       cooperateUnit: "",
    //       duty: "",
    //       userName: "",
    //       phone: "",
    //     },
    //   ];
    // }
    open.value = true;
    //流程图默认不显示
    isShowselectionProcess.value = false;
    //操作轨迹默认不展示
    isShowOperationTrajectory.value = false;
    nextTick(() => {
      if (ProcessVueRef.value != "") {
        ProcessVueRef.value.getListSrc();
      }
      workAreaTree.value.workArea = forma.value.organizationName;
    workAreaTree.value.workAreaId = forma.value.organizationId;
      if (intelligenceVueRef.value != null) {
        intelligenceVueRef.value.getList1();
      }
      //选择工区后重新查询当前桥隧涵的数据
      listbridge({ hasDelete: 0, organizationId: forma.value.organizationId, organizationName: forma.value.organizationName }).then((res) => {
        bridgeList.value = [];
        if (res.code == 200) {
          bridgeList.value = res.data;
        }
      });
    });
  } else {
    proxy.$modal.msgError("请选择任务状态为审核通过的任务进行计划调整");
  }
}
const isSubmitWork = ref(false);
//审批中的提交按钮
function examineForm() {
  if (examineForma.value.action != "") {
    if (examineForma.value.action == "jumpreject" || examineForma.value.action == "reject") {
      if (examineForma.value.comment == "") {
        return proxy.$modal.msgError("更多意见不能为空");
      }
    }
  } else {
    return proxy.$modal.msgError("审批意见不能为空");
  }
  if (examineForma.value.action == "reject" || examineForma.value.action == "jumpreject") {
    examineForma.value.examineStatus = 0;
  } else {
    if (forma.value.examineStatus == "审核中" || forma.value.examineStatus == "作废审核中" || forma.value.examineStatus == "作废驳回") {
      examineForma.value.examineStatus = 0;
    } else {
      examineForma.value.examineStatus = 1;
    }
  }
  if (forma.value.examineStatus == "作废审核中" || forma.value.examineStatus == "作废驳回") {
    examineForma.value.isCance = true;
  } else {
    examineForma.value.isCance = false;
  }
  examineMaintainPlan(examineForma.value).then((res) => {
    if (res.code == 200) {
      if (isShowForm.value.indexOf("详情") == -1) {
        if (submitForm("编辑式审批不提示修改成功") == false) {
          return;
        }
      }
      open.value = false;
      getList();
      return proxy.$modal.msgSuccess("提交成功");
    } else if (res.code == 4) {
      if (isShowForm.value.indexOf("详情") == -1) {
        if (submitForm("编辑式审批不提示修改成功") == false) {
          return;
        }
      }
      res.data.comment = examineForma.value.comment;
      res.data.action = examineForma.value.action;
      submitCheckbox.value = res.data;
      //判断是不是首页的单选提交审批
      isSubmitWork.value = true;
      //判断是不是驳回,false不是
      cancelFunsubmit.value = false;
      isShowselectionProcessDialog.value = true;
    } else if (res.code == 2) {
      if (isShowForm.value.indexOf("详情") == -1) {
        if (submitForm("编辑式审批不提示修改成功") == false) {
          return;
        }
      }
      if (examineForma.value.action == "jumpreject") {
        res.data.comment = examineForma.value.comment;
        res.data.action = examineForma.value.action;
        returnFormobj.value = res.data.nextNode;
        returnNodeShow.value = true;
      } else {
        open.value = false;
        getList();
        return proxy.$modal.msgSuccess("提交成功");
      }
    }
  });
}
//任意驳回
function returnClickFun() {
  if (returnModel.value != "") {
    let obj = {};
    obj.accessToken = sessionStorage.getItem("accessToken");
    obj.planId = examineForma.value.planId;
    obj.trackId = examineForma.value.trackId;
    obj.userName = examineForma.value.userName;
    obj.workId = examineForma.value.workId;
    obj.comment = examineForma.value.comment;
    obj.action = "jumpreject";
    obj.isSelect = true;
    if (obj.action == "jumpreject") {
      obj.examineStatus = 0;
    } else {
      if (forma.value.examineStatus == "审核中" || forma.value.examineStatus == "作废审核中" || forma.value.examineStatus == "作废驳回") {
        obj.examineStatus = 0;
      } else {
        obj.examineStatus = 1;
      }
    }
    let arr = [];
    for (let i = 0; i < returnFormobj.value.length; i++) {
      const element = returnFormobj.value[i];
      if (element.nodeId == returnModel.value) {
        element.isSelect = true;
        arr.push(element);
      }
    }
    obj.nextNodes = arr;
    if (forma.value.examineStatus == "作废审核中" || forma.value.examineStatus == "作废驳回") {
      obj.isCance = true;
    } else {
      obj.isCance = false;
    }
    examineMaintainPlan(obj).then((res) => {
      if (res.code == 200) {
        returnNodeShow.value = false;
        open.value = false;
        proxy.$modal.msgSuccess("提交成功");
        getList();
      }
    });
  } else {
    return proxy.$modal.msgError("退回节点不能为空");
  }
}
/** 保存*/
function submitForm(type) {
  console.log(type);
  for (let i = 0; i < forma.value.outlineList.length; i++) {
    let obj = forma.value.outlineList[i];
    //施工内容
    if (obj.taskId == "") {
      proxy.$modal.msgError("任务Id不能为空");
      return false;
      //施工内容
    } else if (obj.maintainContent == "") {
      proxy.$modal.msgError("施工内容不能为空");
      return false;
      //施工类型
    } else if (obj.maintainType == "") {
      proxy.$modal.msgError("施工类型不能为空");
      return false;
      //线名
    } else if (obj.railwayName == "") {
      proxy.$modal.msgError("线名不能为空");
      return false;
      //行别
    } else if (obj.progressType == "") {
      if (obj.maintainType.slice(0, 3).indexOf("正线") != -1 || obj.maintainType.slice(0, 3).indexOf("站线") != -1) {
        proxy.$modal.msgError("行别不能为空");
        return false;
      }
      //施工地段
    } else if (obj.maintainDistrict == "") {
      proxy.$modal.msgError("施工地段不能为空");
      return false;
      //施工数量
    } else if (obj.maintainNum == "") {
      proxy.$modal.msgError("施工数量不能为空");
      return false;
    }
  }
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      // for (let i = 0; i < forma.value.constructionUnitList.length; i++) {
      //   let obj = forma.value.constructionUnitList[i];
      //   //施工单位
      //   if (obj.constructionUnit == "") {
      //     proxy.$modal.msgError("施工单位不能为空");
      //     return false;
      //     //职务
      //   } else if (obj.duty == "") {
      //     proxy.$modal.msgError("职务不能为空");
      //     return false;
      //     //姓名
      //   } else if (obj.userName == "") {
      //     proxy.$modal.msgError("姓名不能为空");
      //     return false;
      //     //电话
      //   } else if (obj.phone == "") {
      //     proxy.$modal.msgError("电话不能为空");
      //     return false;
      //   }
      // }
      for (let i = 0; i < specialtyobj.value.length; i++) {
        if (specialtyobj.value[i].id == forma.value.specialtyId) {
          forma.value.specialty = specialtyobj.value[i].specialty;
        }
      }
      for (let i = 0; i < constructionLevelobj.value.length; i++) {
        if (constructionLevelobj.value[i].id == forma.value.maintainGradeId) {
          forma.value.maintainGrade = constructionLevelobj.value[i].maintainGrade;
        }
      }
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        for (let a = 0; a < constructionContentobj.value.length; a++) {
          if (forma.value.outlineList[i].maintainContent == constructionContentobj.value[a].maintainContent) {
            forma.value.outlineList[i].maintainContentId = constructionContentobj.value[a].id;
          }
        }
        for (let a = 0; a < progressTypeobj.value.length; a++) {
          if (forma.value.outlineList[i].progressType == progressTypeobj.value[a].progressType) {
            forma.value.outlineList[i].progressTypeId = progressTypeobj.value[a].id;
          }
        }
        for (let a = 0; a < railwayNameobj.value.length; a++) {
          if (forma.value.outlineList[i].railwayName == railwayNameobj.value[a].railwayName) {
            forma.value.outlineList[i].railwayId = railwayNameobj.value[a].id;
          }
        }
        for (let a = 0; a < maintainTypeobj.value.length; a++) {
          if (forma.value.outlineList[i].maintainType == maintainTypeobj.value[a].maintainType) {
            forma.value.outlineList[i].maintainTypeId = maintainTypeobj.value[a].id;
          }
        }
      }
      if (forma.value.id != null) {
        //  yearMonth maintainProject 年月+施工项目唯一
        const objold = JSON.parse(JSON.stringify(forma.value));
        for (const key in editobj.value) {
          for (const keya in forma.value) {
            if (key == "processSteps" || key == "examineStatus") {
              if (editobj.value[key] == forma.value[keya]) {
                Reflect.deleteProperty(objold, keya);
              }
            }
          }
        }
        updateYear(forma.value).then((res) => {
          if (res.code == 200) {
            if (type != "编辑式审批不提示修改成功") {
              proxy.$modal.msgSuccess("修改成功");
              open.value = false;
              getList();
            }
          }
        });
      } else {
        forma.value.examineStatus = type;
        forma.value.createUser = sessionStorage.getItem("userId");
        forma.value.userName = sessionStorage.getItem("userName");
        addYear(forma.value).then((res) => {
          if (res.code == 200) {
            proxy.$modal.msgSuccess("新增成功");
            open.value = false;
            getList();
          }
        });
      }
    }
  });
}
//新建弹窗中的提交审批
function submitForApp() {
  proxy.$refs["form"].validate((valid) => {
    if (valid) {
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        let obj = forma.value.outlineList[i];
        //施工内容
        if (obj.taskId == "") {
          proxy.$modal.msgError("任务Id不能为空");
          return false;
          //施工内容
        } else if (obj.maintainContent == "") {
          proxy.$modal.msgError("施工内容不能为空");
          return false;
          //施工类型
        } else if (obj.maintainType == "") {
          proxy.$modal.msgError("施工类型不能为空");
          return false;
          //线名
        } else if (obj.railwayName == "") {
          proxy.$modal.msgError("线名不能为空");
          return false;
          //行别
        } else if (obj.progressType == "") {
          if (obj.maintainType.slice(0, 3).indexOf("正线") != -1 || obj.maintainType.slice(0, 3).indexOf("站线") != -1) {
            proxy.$modal.msgError("行别不能为空");
            return false;
          }
          //施工地段
        } else if (obj.maintainDistrict == "") {
          proxy.$modal.msgError("施工地段不能为空");
          return false;
          //施工数量
        } else if (obj.maintainNum == "") {
          proxy.$modal.msgError("施工数量不能为空");
          return false;
        }
      }
      // for (let i = 0; i < forma.value.constructionUnitList.length; i++) {
      //   let obj = forma.value.constructionUnitList[i];
      //   //施工单位
      //   if (obj.constructionUnit == "") {
      //     proxy.$modal.msgError("施工单位不能为空");
      //     return false;
      //     //职务
      //   } else if (obj.duty == "") {
      //     proxy.$modal.msgError("职务不能为空");
      //     return false;
      //     //姓名
      //   } else if (obj.userName == "") {
      //     proxy.$modal.msgError("姓名不能为空");
      //     return false;
      //     //电话
      //   } else if (obj.phone == "") {
      //     proxy.$modal.msgError("电话不能为空");
      //     return false;
      //   }
      // }
      for (let i = 0; i < specialtyobj.value.length; i++) {
        if (specialtyobj.value[i].id == forma.value.specialtyId) {
          forma.value.specialty = specialtyobj.value[i].specialty;
        }
      }
      for (let i = 0; i < constructionLevelobj.value.length; i++) {
        if (constructionLevelobj.value[i].id == forma.value.maintainGradeId) {
          forma.value.maintainGrade = constructionLevelobj.value[i].maintainGrade;
        }
      }
      for (let i = 0; i < forma.value.outlineList.length; i++) {
        for (let a = 0; a < constructionContentobj.value.length; a++) {
          if (forma.value.outlineList[i].maintainContent == constructionContentobj.value[a].maintainContent) {
            forma.value.outlineList[i].maintainContentId = constructionContentobj.value[a].id;
          }
        }
        for (let a = 0; a < progressTypeobj.value.length; a++) {
          if (forma.value.outlineList[i].progressType == progressTypeobj.value[a].progressType) {
            forma.value.outlineList[i].progressTypeId = progressTypeobj.value[a].id;
          }
        }
        for (let a = 0; a < railwayNameobj.value.length; a++) {
          if (forma.value.outlineList[i].railwayName == railwayNameobj.value[a].railwayName) {
            forma.value.outlineList[i].railwayId = railwayNameobj.value[a].id;
          }
        }
        for (let a = 0; a < maintainTypeobj.value.length; a++) {
          if (forma.value.outlineList[i].maintainType == maintainTypeobj.value[a].maintainType) {
            forma.value.outlineList[i].maintainTypeId = maintainTypeobj.value[a].id;
          }
        }
      }
      forma.value.examineStatus = "草稿";
      forma.value.createUser = sessionStorage.getItem("userId");
      forma.value.userName = sessionStorage.getItem("userName");
      if (title.value == "年度施工计划新增" || title.value == "年度施工计划调整") {
        addYear(forma.value).then((res) => {
          if (res.code == 200) {
            if (res.data != undefined || res.data != "" || res.data != null) {
              proxy.$modal
                .confirm("请确定是否提交审批？")
                .then(() => {
                  let obj = {
                    accessToken: sessionStorage.getItem("accessToken"),
                    isCreate: true,
                    templateType: "年计划-年度施工轮廓计划-审批",
                    planId: res.data,
                    action: "submit",
                    examineStatus: 1,
                  };
                  examineMaintainPlan(obj).then((res) => {
                    if (res.code == 200) {
                      open.value = false;
                      getList();
                      return proxy.$modal.msgSuccess("提交成功");
                    } else if (res.code == 4) {
                      submitCheckbox.value = res.data;
                      //判断是不是驳回,false不是
                      cancelFunsubmit.value = false;
                      //判断是不是首页的单选提交审批
                      isSubmitWork.value = false;
                      isShowselectionProcessDialog.value = true;
                    }
                  });
                })
                .catch(() => {});
            }
          }
        });
      } else {
        //  yearMonth maintainProject 年月+施工项目唯一
        const objold = JSON.parse(JSON.stringify(forma.value));
        for (const key in editobj.value) {
          for (const keya in forma.value) {
            if (key == "yearMonth" || key == "maintainProject") {
              if (editobj.value[key] == forma.value[keya]) {
                Reflect.deleteProperty(objold, keya);
              }
            }
          }
        }
        updateYear(forma.value).then((res) => {
          if (res.code == 200) {
            if (res.data != undefined || res.data != "" || res.data != null) {
              proxy.$modal
                .confirm("请确定是否提交审批？")
                .then(() => {
                  let obj = {
                    accessToken: sessionStorage.getItem("accessToken"),
                    isCreate: true,
                    templateType: "年计划-年度施工轮廓计划-审批",
                    planId: forma.value.id,
                    action: "submit",
                    examineStatus: 1,
                  };
                  examineMaintainPlan(obj).then((res) => {
                    if (res.code == 200) {
                      open.value = false;
                      getList();
                      return proxy.$modal.msgSuccess("提交成功");
                    } else if (res.code == 4) {
                      submitCheckbox.value = res.data;
                      //判断是不是驳回,false不是
                      cancelFunsubmit.value = false;
                      //判断是不是首页的单选提交审批
                      isSubmitWork.value = false;
                      isShowselectionProcessDialog.value = true;
                    }
                  });
                })
                .catch(() => {});
            }
          }
        });
      }
    }
  });
}
const cancelFunsubmit = ref(false);
//作废计划
function cancelFun(row) {
  proxy.$modal
    .confirm("请确定是否作废该条记录？")
    .then(function () {
      let obj = {
        accessToken: sessionStorage.getItem("accessToken"),
        isCreate: true,
        templateType: "年计划-年度施工轮廓计划-作废",
        planId: row.id,
        action: "submit",
        examineStatus: 2,
        planType: "维修年计划",
        isCance: true,
      };
      examineMaintainPlan(obj).then((res) => {
        if (res.code == 200) {
          open.value = false;
          getList();
          return proxy.$modal.msgSuccess("作废成功");
        } else if (res.code == 4) {
          //判断是不是首页的单选提交审批
          isSubmitWork.value = true;
          //判断是不是驳回,true是
          cancelFunsubmit.value = true;
          submitCheckbox.value = res.data;
          isShowselectionProcessDialog.value = true;
        }
      });
    })
    .then(() => {})
    .catch(() => {});
}
/** 删除按钮操作 */
function handleDelete(row) {
  proxy.$modal
    .confirm("请确定是否删除该条记录？")
    .then(function () {
      deleteRelevanceById({ id: row.id }).then((res) => {
        if (res.code == 200) {
          getList();
          proxy.$modal.msgSuccess("删除成功");
        }
      });
    })
    .then(() => {})
    .catch(() => {});
}
</script>
<style scoped lang="scss">
.el-form--inline .el-form-item.formitemcla {
  margin-right: 5px !important;
}
.concentDiv {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
  margin-bottom: 5px;
}
.dialogcon {
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.titlecla {
  height: 30px;
  background-color: #4080ff;
  color: #fff;
  line-height: 30px;
  padding-left: 20px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 5px;
  margin-top: 5px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.titlecla1 {
  height: 30px;
  background-color: #94bfff;
  color: #fff;
  line-height: 30px;
  padding-left: 20px;
  font-weight: 600;
  font-size: 16px;
  margin-bottom: 5px;
  margin-top: 5px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}
.butclas1 {
  margin-top: 5px;
  height: 30px;
}
.divclass {
  display: flex;
  flex-direction: row;
  justify-content: center;
  width: 100%;
}
.rightdiv {
  width: 100%;
  // width: 1190px;
}

.calssdivsub {
  margin-top: 10px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
.icon {
  width: 20px;
  height: 20px;
  display: inline-block;
  margin-right: 3px;
  color: #004bff;
}
.icon:hover {
  color: #000dff;
  cursor: pointer;
}
.divzanwu {
  width: 100%;
  height: 150px;
  display: flex;
  justify-content: center;
  align-items: center;
}
::v-deep(.tabradio .cell) {
  visibility: hidden;
}
.CirclePlusFilled {
  font-size: 18px;
}
.formItembz {
  margin-right: 0px !important;
}
.inputDiv {
  display: flex;
  // justify-content: space-between;
}
</style>
